Yii CFileCache似乎没有删除过期的缓存

Yii CFileCache似乎没有删除过期的缓存

问题描述:

I seem to have some problem when using CFileCache in Yii. It seem doesn't delete the expired cache automatically.

Here is my configuariton in main.php:

    'cache'=>array(
        'class'=>'system.caching.CFileCache',
        'embedExpiry' => true
    )

here is how I set the cache in my controller with 30 seconds expired time:

 Yii::app()->cache->set("mykey", "somedata", 30);

Is there something wrong with my configuration or my code? I really need this to be solve. Thanks

As you are using the CFileCache, you can use the following things to clear the cache

  1. Yii::app()->cache->flush();. This will remove all the Cached data, ie the files from the folder 'runtime'.
  2. Yii::app()->cache->gc();. This will only remove the expired cache data

What do you mean by delete? As per the API description provided in http://www.yiiframework.com/doc/api/1.1/CCache if the data item expires then get will return false. Did you run the get method after 30 sec and check for the return value?