I have a fragment that I'm caching because there are a lot of database hits to generate the content.
main.php:
'cache'=>array(
'class'=>'system.caching.CFileCache'
)
view.php
<?php if($this->beginCache("my_id", array('duration' => 315360000))) { ?>
// lots of heavy stuff
<?php $this->endCache(); } ?>
My cached fragment only changes when I adjust the configuration in a database table. I'm trying to find a way to delete the cached item using the "my_id". The Yii documentation is somewhat misleading because when it talks about beginCache
it refers to the key ("my_id"), but when it talks about deleting items from the cache it also talks about the key, but it is not the same key!
beginCache
is essentially a wrapper for an COutputCache
widget and so "my_id" is not the key used in the cache.
Does anyone know how to convert "my_id" into a cache-friendly key so that I can delete that specific item from the cache.
I've tried extending from CFileCache
but my key is generated from COutputCache
which uses CFileCache
and I don't think there is a back route. I have also tried beginning a widget with an overloaded version of COutputCache
which works but just seems like a really nasty hack.
$properties = array();
$properties['id']=Yii::app()->params["cache_name_matrix"];
$cache=$this->beginWidget('MyCOutputCache',$properties);
$key = $cache->getKeyHack();
My current work around is flush the whole cache but this gets rid of everything and seems a little bit heavy handed.
Any ideas?