Zend Cache Cleanup Templates

I started using Zend Cache (APC backend), and everything is fine in terms of returning cached values, and not to hit the database every time. However, my problem is:

$cache_key = 'getrebates_'.$operator_code; if(PP_Model_CacheService::exists($cache_key)) { $cached_values = PP_Model_CacheService::load($cache_key); } else { //hits the db $cached_values = $this->getAll($operator_code); PP_Model_CacheService::save($cached_values, $cache_key); } return $cached_values; 

Each operator has its own discounts that vary between operators, now if I change the database and I need to clear the discounts for all operators, how would I do it?

I can use $ Cache-> clean () , but this will clear the other caches (and not just the discount cache for each statement). If I go through all the operators:

 foreach($operator_codes AS $operator_code) { $cache_key = 'getrebates_'.$operator_code; $cache->delete($cache_key) } 

It looks like a cache job. Is there a way to clear only part of the cache.

 //Something like: $section_key = 'getrebates'; $Cache[$section_key][$operator_code]; $Cache->clearSection($section_key); 

Is there any array structure in the APC cache or is it all key-based cache / value?

+6
source share
2 answers

You can apply tags to values ​​stored in the cache. This way, you can easily delete all cache entries that have a specific tag.

 $cache->save($huge_data, 'myUniqueID', array('tagA', 'tagB')); // clear all cache entries with tag tagA or tagC $cache->clean( Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('tagA', 'tagC') ); 

Refer to this page: http://framework.zend.com/manual/en/zend.cache.theory.html and the API for details on the pure Zend_Cache_Core method: http://framework.zend.com/apidoc/1.11 /

+10
source

@theduke is right, tagging is the right way to do this, except for APC, since Zend_Cache_Backend_Apc does not support tagging . From the doc :

Be careful: with this backend, "tags" are not currently supported

And from your last comment in sems, you are using APC as a backend. Thus, either you extend this class or add tag behavior (by adding special syntax to the tag identifier? By processing tag binding vs cache entry elsewhere?) In a long-term cache entry?) Or did you decide to use a different cache backend.

+4
source

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


All Articles