Cache Valid Until The Next Day


the Cache method of yii has the parameter cache time to set the cache e.g. 10 minutes valid. I want to set the cache valid until the next day (midnight).

Do you know if this feature is built-in yii? I could use CDbCacheDependency and do:

Yii::app()->cache->set($id, 0, new CDbCacheDependency('SELECT CURDATE();'));

Is this the way to go? Or is there a better way without using db?

My fist idea: create a new CacheDependency class, for example:

class CurrentDateCacheDependency extends CCacheDependency


        public $format;

        public function __construct($format=null)




        protected function generateDependentData()



                        return date($this->format);


                        throw new CException(Yii::t('ext','CurrentDateCacheDependency.format cannot be empty.'));




Yii::app()->cache->set($id,$value,0,new CurrentDateCacheDependency('Ymd'));