0
我想緩存一些東西。在我core.php中的配置文件,我有這樣的:CakePHP:緩存可以寫入文件但不能讀取它(總是爲false)
//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,
));
在我的控制器
,我有這樣的:
$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;
我可以看到生成的文件 - /路徑/到/緩存/ cake_short_xmlpublist
但是當我Cache::read('xmlpublist')
,我總是得到bool(false)
。我確信我已經讀取和寫入了緩存目錄。
期望值: 從緩存中獲取值。
結果: 我得到布爾(假)
如果可能我哪裏呢?
任何答覆讚賞;)
感謝, W¯¯
太棒了。這工作。我檢查了http://book.cakephp.org/2.0/en/core-libraries/caching.html#CacheEngine::read並且文檔中沒有第二個參數。 – wenbert
我認爲你在查看CacheEngine :: read()文檔,而不是Cache :: read()。你想看看http://book.cakephp.org/2.0/en/core-libraries/caching.html#cache-api –