2014-01-11 71 views
0

我使用Kohana 2.x,我想爲數據庫結果實現緩存。對於我嘗試如下,Kohana 2.x緩存問題

$cache = Cache::instance(); 
$siteSettings = $cache->get('siteSettings'); 
if (! $siteSettings) 
{ 
    // for 1st request only it entering, this I've verified  
    $siteSettings = ORM::factory('siteSettings', 1); 
    $cache->set('siteSettings', $siteSettings, array('siteSettings'), 0); 
} 

之後,如果我嘗試訪問表列作爲

$siteSettings->adminEmail; 

雖然再次進入數據庫,即使它沒有進入上述if條件。我在哪裏犯錯?我正在使用文件緩存,並確保該文件夾具有可寫權限,並且我已驗證它具有數據庫結果的緩存文件。

編輯:

以下是我的緩存設置

$config['default'] = array(
    'driver' => 'file', 
    'params' => APPPATH.'cache', 
    'lifetime' => 1800, 
    'requests' => -1 
); 

回答

0

我們應該有

// Prevents cached items from being reloaded 
protected $reload_on_wakeup = FALSE; 

在相應的表格模型類。

0

緩存不工作,因爲你沒有設置time period

$cache->set('siteSettings', $siteSettings, array('siteSettings'), 0); 

您覆蓋在時段3600秒默認設置(U盤0)。爲緩存的生命週期設置時間。

+0

我認爲時間爲零意味着全職,直到我清除自己的緩存。雖然我試過的時間段值爲3600,即使是第二次請求它打到db。 –

+0

@ Mahesh.D是否檢查過緩存驅動程序的所有設置? – voodoo417

+0

@ Mahesh.D,爲什麼不是$ cache-> set('siteSettings',$ siteSettings); ? – voodoo417