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
);
我認爲時間爲零意味着全職,直到我清除自己的緩存。雖然我試過的時間段值爲3600,即使是第二次請求它打到db。 –
@ Mahesh.D是否檢查過緩存驅動程序的所有設置? – voodoo417
@ Mahesh.D,爲什麼不是$ cache-> set('siteSettings',$ siteSettings); ? – voodoo417