2012-08-27 40 views
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¯¯

回答

5

當調用Cache::read()你需要包括緩存配置從,看了那麼你的情況'short'。沒有那個額外的參數,你會從'默認'配置中讀取,該配置可能沒有你正在尋找的密鑰。

+0

太棒了。這工作。我檢查了http://book.cakephp.org/2.0/en/core-libraries/caching.html#CacheEngine::read並且文檔中沒有第二個參數。 – wenbert

+1

我認爲你在查看CacheEngine :: read()文檔,而不是Cache :: read()。你想看看http://book.cakephp.org/2.0/en/core-libraries/caching.html#cache-api –

相關問題