Welcome to the Cookbook

loading...
Please login to continue

8.7.4 Cache::config()

There is no translation yet for this section. Please help out and translate this.. More information about translations

Cache::config() is used to create additional Cache configurations. These additional configurations can have different duration, engines, paths, or prefixes than your default cache config. Using multiple cache configurations can help reduce the number of times you need to use Cache::set() as well as centralize all your cache settings.

You must specify which engine to use. It does not default to File.

Cache::config('short', array(  
    'engine' => 'File',  
    'duration'=> '+1 hours',  
    'path' => CACHE,  
    'prefix' => 'cake_short_'
));

// long  
Cache::config('long', array(  
    'engine' => 'File',  
    'duration'=> '+1 week',  
    'probability'=> 100,  
    'path' => CACHE . 'long' . DS,  
));
  1. Cache::config('short', array(
  2. 'engine' => 'File',
  3. 'duration'=> '+1 hours',
  4. 'path' => CACHE,
  5. 'prefix' => 'cake_short_'
  6. ));
  7. // long
  8. Cache::config('long', array(
  9. 'engine' => 'File',
  10. 'duration'=> '+1 week',
  11. 'probability'=> 100,
  12. 'path' => CACHE . 'long' . DS,
  13. ));

By placing the above code in your app/config/core.php you will have two additional Cache configurations. The name of these configurations 'short' or 'long' is used as the $config parameter for Cache::write() and Cache::read().