Welcome to the Cookbook

loading...

8.7.5 Cache::set()

Cache::set() allows you to temporarily override a cache configs settings for one operation (usually a read or write). If you use Cache::set() to change the settings for a write, you should also use Cache::set() before reading the data back in. If you fail to do so, the default settings will be used when the cache key is read.


Cache::set(array('duration' => '+30 days'));
Cache::write('results', $data);

// Later on

Cache::set(array('duration' => '+30 days'));
$results = Cache::read('results');
  1. Cache::set(array('duration' => '+30 days'));
  2. Cache::write('results', $data);
  3. // Later on
  4. Cache::set(array('duration' => '+30 days'));
  5. $results = Cache::read('results');

If you find yourself repeatedly calling Cache::set() perhaps you should create a new Cache configuration. This will remove the need to call Cache::set().