Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cakephp/cache
[READ-ONLY] Easy to use Caching library with support for multiple caching backends. This repo is a split of the main code that can be found in https://github.com/cakephp/cakephp
https://github.com/cakephp/cache
Last synced: about 2 months ago
JSON representation
[READ-ONLY] Easy to use Caching library with support for multiple caching backends. This repo is a split of the main code that can be found in https://github.com/cakephp/cakephp
- Host: GitHub
- URL: https://github.com/cakephp/cache
- Owner: cakephp
- License: other
- Created: 2014-10-01T13:06:49.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-03-09T03:36:57.000Z (3 months ago)
- Last Synced: 2024-03-13T14:07:26.530Z (3 months ago)
- Language: PHP
- Homepage:
- Size: 16.4 MB
- Stars: 51
- Watchers: 28
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Lists
- awesome-php - CakePHP Cache - A caching library. (Table of Contents / Caching and Locking)
- awesome-projects - CakePHP Cache - A caching library. (PHP / Caching and Locking)
- awesome-php-zh_CN - Cake Cache - 一个缓存库 (CP) (缓存 Caching)
- awesome-php-cn - CakePHP Cache - 缓存库. (目录 / 缓存和锁定 Caching and Locking)
- awesome-php - Cake Cache - 一个用于缓存的库 (缓存( Caching ))
- awesome-php - Cake Cache - A caching library (CP). (Caching)
- awesome-php - CakePHP Cache - A caching library. (Table of Contents / Caching and Locking)
- awesome-php-new - CakePHP Cache - A caching library. (Table of Contents / Caching)
- awesome-php - Cake Cache - A caching library (CP). (Caching)
- awesome-php - CakePHP Cache - A caching library. (Table of Contents / Caching)
- awesome-php - CakePHP Cache - A caching library. (Table of Contents / Caching)
- PHP_awesome-directus-duh-REKT-iss- - CakePHP Cache - A caching library. (Table of Contents / Caching)
- awesome-php - Cake Cache - 一个用于缓存的库 (URL)
- awesome-stripe - CakePHP Cache - A caching library. (Table of Contents / Caching)
- awesome-php - CakePHP Cache - A caching library. (Table of Contents / Caching)
- awesome-php - CakePHP Cache - A caching library. (Table of Contents / Caching and Locking)
- awesome-php - CakePHP Cache - A caching library. (Table of Contents / Caching and Locking)
- awesome-php - Cake Cache - 一个用于缓存的库 (缓存( Caching ))
README
# CakePHP Caching Library
The Cache library provides a `Cache` service locator for interfacing with multiple caching backends using
a simple to use interface.The caching backends supported are:
* Files
* APC
* Memcached
* Redis
* Wincache
* Xcache## Usage
Caching engines need to be configured with the `Cache::config()` method.
```php
use Cake\Cache\Cache;// Using a short name
Cache::config('default', [
'className' => 'File',
'duration' => '+1 hours',
'path' => sys_get_tmp_dir(),
'prefix' => 'my_app_'
]);// Using a fully namespaced name.
Cache::config('long', [
'className' => \Cake\Cache\Engine\ApcuEngine::class,
'duration' => '+1 week',
'prefix' => 'my_app_'
]);// Using a constructed object.
$object = new FileEngine($config);
Cache::config('other', $object);
```You can now read and write from the cache:
```php
$data = Cache::remember('my_cache_key', function () {
return Service::expensiveCall();
});
```The code above will try to look for data stored in cache under the `my_cache_key`, if not found
the callback will be executed and the returned data will be cached for future calls.## Documentation
Please make sure you check the [official documentation](https://book.cakephp.org/4/en/core-libraries/caching.html)