使用YII缓存注意事项

在使用YII自身缓存时,在main.php文件配置中一定要配置keyPrefix,如下图:

 

'cache' => array(
  'class' => 'CFileCache',
  'keyPrefix' => 'ivyonline',
),

如果不配置,造成缓存删除不了的问题(另:自己生成的缓存,自己可以删除),上YII源码如下:

/**
* Initializes the application component.
* This method overrides the parent implementation by setting default cache key prefix.
*/
public function init()
{
      parent::init();
      if($this->keyPrefix===null)
           $this->keyPrefix = Yii::app()->getId();
      }

/**
* @param string $key a key identifying a value to be cached
* @return string a key generated from the provided key which ensures the uniqueness across applications
*/
protected function generateUniqueKey($key)
{
       return $this->hashKey ? md5($this->keyPrefix.$key) : $this->keyPrefix.$key;
}

posted @ 2015-12-01 15:51  乡村猫  阅读(253)  评论(0编辑  收藏  举报