|
5 anni fa | |
---|---|---|
.. | ||
Engine | 5 anni fa | |
Cache.php | 5 anni fa | |
CacheEngine.php | 5 anni fa | |
CacheEngineInterface.php | 5 anni fa | |
CacheRegistry.php | 5 anni fa | |
InvalidArgumentException.php | 5 anni fa | |
README.md | 5 anni fa | |
SimpleCacheEngine.php | 5 anni fa | |
composer.json | 5 anni fa |
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:
Caching engines need to be configured with the Cache::config()
method.
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',
'duration' => '+1 week',
'prefix' => 'my_app_'
]);
// Using a constructed object.
$object = new FileEngine($config);
Cache::config('other', $object);
You can now read a write from the cache:
$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.
Please make sure you check the official documentation