I am trying to cache something. In my core.php config file, I have this:
//short
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,
));
in my controller, I have this:
$xmlpublist = Cache::read('xmlpublist');
var_dump($xmlpublist);
//if cache is still set, return cache
if($xmlpublist !== false) {
die('cache A');
return $xmlpublist;
}
Cache::write('xmlpublist', "test", 'short');
die('cache C');
return $xml;
I can see that the file is generated – /path/to/cache/cake_short_xmlpublist
But when I Cache::read('xmlpublist'), I always get bool(false). I made sure that I have both read and write access to the cache directory.
Expectation:
Get values from the cache.
Result:
I get bool(false)
Where could have I gone wrong?
Any reply appreciated 😉
Thanks,
W
When calling
Cache::read()you need to include the cache configuration to read from, so in your case'short'. Without that additional parameter you’ll be reading from the ‘default’ config which probably doesn’t have the key you’re looking for.