Hi
I am trying to make use of the CCacheDependency class to control the COutputCache widget. The problem is I have the generateDependentData value already retrieved, so I do not want to refetch this value. But I am having problems indicating this to the COutputCache widget.
I tried
class ZCacheDependency extends CCacheDependency {
public $updateDate=false;
public function generateDependentData() {
return $this->updateDate;
}
}
And in creating the widget I do
$dependency = new ZCacheDependency;
$keys = array('id'=>$route.
" ".$content->moduleDataId,
'dependency'=>$dependency);
$dependency->updateDate = $content->updateDate;
$cache = $this->createWidget('COutputCache',$keys);
...
But this does not work as expected because the ZCacheDependency is serialized and the new instance is not used when checking to see if the cache is valid.
So I changed things to do this
class ZCacheDependency extends CCacheDependency {
public $updateDate=false;
public function generateDependentData() {
return Yii::app()->params['updateDate'];
}
}
Yii::app()->params['updateDate'] = $content->updateDate;
$dependency = new ZCacheDependency;
$keys = array('id'=>$route.
" ".$content->moduleDataId,
'dependency'=>$dependency);
$cache = $this->createWidget('COutputCache',$keys);
Ugly but it works, I guess I could also have used a static value also, but is there a better way ?
Thanks
nz