Yii中缓存依赖的处理

一重点数据库

 

public function getPmByName($city)
{
    if($info = Yii::app()->cache->get("$city")){
         return $info;
    }
    $sql = "select city_info from pm25 where city_name = '{$city}' limit 1"; //这样写目的是为了下面依赖
    $cmd = Yii::app()->db->createCommand($sql)->queryScalar();
    if($cmd){
           Yii::app()->cache->set($city, $cmd, 3600 ,new CDbCacheDependency($sql));
    }

    return $cmd?$cmd:0;
}

posted @ 2014-02-25 19:19  zyliang  阅读(231)  评论(0编辑  收藏  举报