While working out how to do caching for my CakePHP app with some builtin ACL permissions goodies, I came across this error message:
Warning (512): Cache not configured properly. Please check Cache::config(); in APP/config/core.php [CORE/cake/libs/configure.php, line 408]
I’ll cut the long story short and tell you what I did wrong so you don’t repeat the same mistake.
The Setup
As you might have already know, you configure/enable/disable caching in cakeapp/congif/core.php
Configure::write(‘Cache.disable’, false);
Configure::write(‘Cache.check’, true);
The default cache configuration is:
Cache::config(‘default’, array(‘engine’ => ‘File’));
I wanted to use (or should i say, add) another cache configuration which is
Cache::config(‘one day’, array(‘engine’ => ‘File’, ‘duration’ => ‘+1 day’));
The Mistake
I commented the default cache configuration. Try it. You will get the same error message above.
//Cache::config(‘default’, array(‘engine’ => ‘File’));
Cache::config(‘one day’, array(‘engine’ => ‘File’, ‘duration’ => ‘+1 day’));
The Solution
You need a default cache configuration.
If there are extra cache configurations, just give them a different name, duration and/or engine etc.
Example:
Cache::config(‘default’, array(‘engine’ => ‘File’));
Cache::config(‘one day’, array(‘engine’ => ‘File’, ‘duration’ => ‘+1 day’));
Writing/Reading with different cache configuration
So let’s say you want to write/read some data to/from the cache with both cache configuration, here’s how you do it:
Cache:write(“keyname”) // write cache using default cache configuration
Cache:write(“keyname2”, ‘one day’) // write cache using the ‘one day’ cache confiiguration
For reading, substitute write with read.
Hope this helps.
Kannon Yamada says
Thanks it works.