查询缓存 yii 框架


Query caching yii framework

我想找到登录用户的总分并想要缓存它。我的代码是:

$dependency = new CDbCacheDependency('SELECT MAX(id) FROM tbl_points_log where user_id='.Yii::app()->user->id);    
$sql='SELECT SUM( point) as user_point FROM tbl_points_log left join tbl_action on tbl_action.id = tbl_points_log.action_type_id where user_id='.Yii::app()->user->id;
$user_point = Yii::app()->db->cache(1000, $dependency)->createCommand($sql)->queryAll();

上面的代码正确吗?我是否必须在配置文件中进行一些更改才能使查询缓存正常工作?我刚刚添加了

'cache' => array(
     'class' => 'CDbCache'
 ),

在组件下

var_dump($dependency->getHasChanged());总是计算为 true,即使我没有对数据库进行任何更改,为什么会这样呢?

附言不要为SQL语句而烦恼。它的工作!

找出

查询结果来自缓存或数据库的最佳方法是按如下方式打开日志记录并查看结果

        'log'=>array(
            'class'=>'CLogRouter',
            'routes'=>array(
                array(
                    'class'=>'CFileLogRoute',
                    'levels'=>'error, warning',
                ), 
                array(
                    'class'=>'CWebLogRoute',
                ), 
            ),
        ),