Php 过期时间在缓存中出错
我使用文件缓存(CFileCache)来显示来自数据库表的简单消息。 当第一次加载页面时,它工作正常,但当我重新加载页面时,它会出现以下错误: include(CTimestampBehavior.php)[function.include]:无法打开流:没有这样的文件或目录 这个错误一直持续到我在cache->set()中设置的时间到期,下一个页面只加载一次,它就会再次出错,以此类推 以下是我处理缓存的方法:Php 过期时间在缓存中出错,php,caching,yii,Php,Caching,Yii,我使用文件缓存(CFileCache)来显示来自数据库表的简单消息。 当第一次加载页面时,它工作正常,但当我重新加载页面时,它会出现以下错误: include(CTimestampBehavior.php)[function.include]:无法打开流:没有这样的文件或目录 这个错误一直持续到我在cache->set()中设置的时间到期,下一个页面只加载一次,它就会再次出错,以此类推 以下是我处理缓存的方法: public static function getLatest() {
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和caching是新手,对此一无所知
更新:
AR模型的行为方法:
public function behaviors()
{
return array(
'CTimestampBehavior' => array(
'class' => 'zii.behaviors.CTimestampBehavior',
'createAttribute' => 'create_time',
'updateAttribute' => 'update_time',
'setUpdateOnCreate' => true,
),
);
}
您的问题可能是:
- 缺少framework/zii/behaviors/CTimestampBehavior.php
- framework/zii/behaviors/CTimestampBehavior.php没有服务器用户可以读取的正确权限
- 您使用的是操作码缓存(APC?),在这方面存在一些问题(尽管有关这方面的报告似乎是针对随机事件的)。尝试禁用它
- 出于未知原因,Yii不会导入您的zii路线
如果没有,您可以调查上述情况(至少到这里来的人会有更多的信息要处理)您在哪里指定
CTimestampBehavior
?我扩展了CActiveRecord并创建了一个抽象类,将CTimestampBehavior作为行为(使用behaviors()方法)添加到整个AR模型中。getLatest()生活在其中一个模型中。你能展示行为方法吗?好的,我用它更新了我的问题。谢谢。导入方法奏效了。似乎Yii base不会导入zii路由,因为所有zii组件在我的web应用程序中都可以正常工作。我不知道我如何才能检查Yii基地的zii路线。顺便说一句,我确信权限没有问题。