How to selectively clear the cache (using tags or another option) with the Memchached backend and Zend Framework

We use Memcached and Zend Framework in our web project. Now we need to clean the cache selectively using tags, as specified in the Zend_Cache API .

Unfortunately, memcached does not support tags .

I found these workarounds:

Thanks in advance

+3
source share
1 answer

You're right. Memcache does not support tags.

You can use a different key value to implement the tag for memcache.

EX:

$this->objCache->save($arrResults, $strKey,array($strMyTag),$intCacheTime) // note : array($strMyTag) don't work for Memcache MemcacheTag::setTag($strKey, $strMyTag) // our work around 

About the setTag and MemcacheTag method:

 function setTag($strKey,$strTag){ $arrKey = $cacheOjb->get($strTag); $arrKey[]= $strKey; } function deleteCacheWithTag($strTag){ $arrKey = $cacheOjb->get($strTag); foreach ($arrKey as $strKey){ $objCache->delete($strKey); } } 

This work is pretty simple and works for my projects.

* Note: these codes need modification; sorry for posting in a hurry

+2
source

Source: https://habr.com/ru/post/889695/


All Articles