Jeremy Harris 7ed418d6e8 Quick typo fix in cache readme 11 years ago
..
Engine 948cfc0053 Removing magic cache prefix as APP_DIR is always src 11 years ago
Cache.php 608e1c5ae7 Add space after closures' function keyword 11 years ago
CacheEngine.php 2527d9ebd7 Remove unused use imports 11 years ago
CacheRegistry.php 58784a5276 fix CS 11 years ago
README.md 7ed418d6e8 Quick typo fix in cache readme 11 years ago
composer.json 30b8b6f63b Adding composer.json and Readme to Cache 11 years ago

README.md

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.

use Cake\Cache\Cache;

// Using a short name
Cache::config('default', array(
    'className' => 'File',
    'duration' => '+1 hours',
    'path' => sys_get_tmp_dir(),
    'prefix' => 'my_app_'
));

// Using a fully namespaced name.
Cache::config('long', array(
    'className' => 'Cake\Cache\Engine\ApcEngine',
    '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.

Documentation

Please make sure you check the official documentation