CMemcache doesn't allow me to delete cache id

i need to manually unset/invalidate a fragment cache (i use $this->beginCache('left-menu', array('duration'=>86400)) to create the cache) with a specific id in some actions so i use:

$return = Yii::app()->cache->delete('MyKeyString');

…but the cache is not invalidate infact the delete() method always return false…why?

The cache key used by output cache is more complicated than the id you provide in beginCache()…

Quote

The cache key used by output cache is more complicated than the id you provide in beginCache()...
sorry i didn't understand this....what do you mean?

I mean beginCache('left-menu') does not use 'left-menu' as the underlying cache key. It combines other information to implement cache variation.

Quote

I mean beginCache('left-menu') does not use 'left-menu' as the underlying cache key. It combines other information to implement cache variation.
ok so how what is the right use? The manual says that we can set the key as a string and that we can delete/invalidate the cache passing that key string to the delete method....so how can i invalidate my cache?

You would have to have a way generate the key that Yii is generating when it sets the cache key.

I know for setting the item it's a combination of a prefix which is usually blank and then using md5 to generate the key that is stored. I discovered this when i was trying to view a item i cached as a test using telnet to connect to the daemon.

Quote

You would have to have a way generate the key that Yii is generating when it sets the cache key.

I know for setting the item it's a combination of a prefix which is usually blank and then using md5 to generate the key that is stored. I discovered this when i was trying to view a item i cached as a test using telnet to connect to the daemon.

sorry i still don't understand. What is the purpose of the delete method if i cannot use it?

Quote

I mean beginCache('left-menu') does not use 'left-menu' as the underlying cache key. It combines other information to implement cache variation.
so can you explain us how to clear/invalidate a cache setted with CController::beginCache() method knowing that i passed to that method a string as a cache key?

This is currently not possible. The reason is that: given your id, the actual key to the cache is calculated as func(id, other factors). The factors include GET parameters, session parameters, etc. As you can, a single ID may correspond to multiple cache entries.

We may considering adding a support to delete cache items based on partial match of cache keys. Could you please create a ticket for this? Thanks.

Quote

This is currently not possible. The reason is that: given your id, the actual key to the cache is calculated as func(id, other factors). The factors include GET parameters, session parameters, etc. As you can, a single ID may correspond to multiple cache entries.

We may considering adding a support to delete cache items based on partial match of cache keys. Could you please create a ticket for this? Thanks.

mmm…so right now how can i delete a particular cache created with beginCache? Only setting a expire time or dependency check?

can you also explain me the purpose (and when we can use it) of the delete() method if i cannot use it to invalidate the cache?

The delete operation is used to delete a data item that you store directly via Yii::app()->cache->set() or add(). COutputCache is different because there may not be a one-to-one mapping between ID and the underlying cache key.

Quote

The delete operation is used to delete a data item that you store directly via Yii::app()->cache->set() or add(). COutputCache is different because there may not be a one-to-one mapping between ID and the underlying cache key.
ok understand. So how i invalidate/delete a fragment cache? Only with expire time or dependecy check?

Yes, that's the only option right now.

You could try recaching the fragment and specify 1 for it's ttl.

That way after 1 sec it would expire.

Perhaps the fragment cache could be modified to return the encode key as stored in the cache

i tried:



 if($this->beginCache('myId', array('duration' => 3600) {





    // content to cache


    $this->endCache();





}


But with the help of the logs i see that the application doesn't cache 'cause everytime it executes the code in the if statement

Did you enable 'cache' component?

Quote

Did you enable 'cache' component?
yes i got:


 'cache'=>array(


                            'class'=>'system.caching.CMemCache',


                            'servers'=>array(array('host'=>'localhost', 'port'=>11211, 'weight'=>60)),


                 ),


in my config

I see no reason why this wouldn't work unless your memcache has problem. Try with a CDbCache?

Quote

I see no reason why this wouldn't work unless your memcache has problem. Try with a CDbCache?
sorry you are right i didn't have the memcached daemon started :)