lxy254069025 2012-11-29 13:57:58 4207次浏览 1条回复 0 0 0

方便简单,在你的模型中加入以下代码便可,你得在main文件中配置缓存存在哪。

public function cache($duration = null, $dependency = null)
{
    if ($duration === null)
        $duration = 3600 * 12 * 7;
    if ($dependency === null)
        $dependency = new CDbCacheDependency("SELECT COUNT(*), MAX(update) FROM ".$this->tableName());//如果总记录或者update这个字段没有更新那么缓存就不会更新,如果没有update这个字段可以去掉 MAX(update)
    return parent::cache($duration, $dependency);
}

结束!

您需要登录后才可以回复。登录 | 立即注册