我正在使用文件缓存 (CFileCache) 来显示来自数据库表的简单消息。第一次加载页面时它可以正常工作,但是当我重新加载页面时它会出错:include(CTimestampBehavior.php)[function.include]:无法打开流:没有这样的文件或目录
并且此错误一直存在,直到我在 cache->set() 中设置的 TIME EXPIRATION 并且下一页仅加载一次,然后再次出错,依此类推。
这是我处理缓存的方法:
public static function getLatest()
{
//see if it is in the cache, if so, just return it
if( ($cache=Yii::app()->cache)!==null)
{
$key='TrackStar.ProjectListing.SystemMessage';
if(($sysMessage=$cache->get($key))!==false)
return $sysMessage;
}
//The system message was either not found in the cache, or
//there is no cache component defined for the application
//retrieve the system message from the database
$sysMessage = SysMessage::model()->find(array(
'order'=>'t.update_time DESC',
));
if($sysMessage != null)
{
//a valid message was found. Store it in cache for future retrievals
if(isset($key))
//$cache->set($key,$sysMessage,300);
$cache->set($key, $sysMessage, 300, new CDbCacheDependency('SELECT MAX(update_time) FROM tbl_sys_message'));
return $sysMessage;
}
else
return null;
}
此行出现错误:
if(($sysMessage=$cache->get($key))!==false)
我是 Yii 和缓存的新手,对此一无所知。
更新:AR模型的行为方法:
public function behaviors()
{
return array(
'CTimestampBehavior' => array(
'class' => 'zii.behaviors.CTimestampBehavior',
'createAttribute' => 'create_time',
'updateAttribute' => 'update_time',
'setUpdateOnCreate' => true,
),
);
}