Issues

ZF-4681: New cleaning mode CLEANING_MODE_MATCHING_ANY_TAG

Description

Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG mode for cache clean method that will remove all cache items containing any tag passed to clean method.

For Zend_Cache_Backend_File

 
Index: Zend/Cache.php
===================================================================
--- Zend/Cache.php  (revision 12080)
+++ Zend/Cache.php  (working copy)
@@ -72,6 +72,7 @@
     const CLEANING_MODE_OLD              = 'old';
     const CLEANING_MODE_MATCHING_TAG     = 'matchingTag';
     const CLEANING_MODE_NOT_MATCHING_TAG = 'notMatchingTag';
+    const CLEANING_MODE_MATCHING_ANY_TAG = 'MatchingAnyTag';
 
     /**
      * Factory
Index: Zend/Cache/Core.php
===================================================================
--- Zend/Cache/Core.php (revision 12080)
+++ Zend/Cache/Core.php (working copy)
@@ -416,7 +416,7 @@
         if (!$this->_options['caching']) {
             return true;
         }
-        if (!in_array($mode, array(Zend_Cache::CLEANING_MODE_ALL, Zend_Cache::CLEANING_MODE_OLD, Zend_Cache::CLEANING_MODE_MATCHING_TAG, Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG))) {
+        if (!in_array($mode, array(Zend_Cache::CLEANING_MODE_ALL, Zend_Cache::CLEANING_MODE_OLD, Zend_Cache::CLEANING_MODE_MATCHING_TAG, Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG, Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG))) {
             Zend_Cache::throwException('Invalid cleaning mode');
         }
         self::_validateTagsArray($tags);
Index: Zend/Cache/Backend/File.php
===================================================================
--- Zend/Cache/Backend/File.php (revision 12080)
+++ Zend/Cache/Backend/File.php (working copy)
@@ -682,6 +682,14 @@
                             $result = ($result) && $this->remove($id);
                         }
                         break;
+                   case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
+                        foreach ($tags as $tag) {
+                            if (in_array($tag, $metadatas['tags'])) {
+                                $result = ($result) && $this->remove($id);
+                                break 2;
+                            }
+                        }
+                        break;                        
                     default:
                         Zend_Cache::throwException('Invalid mode for clean() method');
                         break;

Comments

now, you can do call CLEANING_MODE_MATCHING_TAG each time (tag by tag) in your code

but why not, it sounds as a good idea

Suppose you have 3 items with tags:

'item_1', array( 'items', 'item_1' ); 'item_2', array( 'items', 'item_2' ); 'photo_121', array( 'photos', 'item_1', 'photo_121');

With CLEANING_MODE_MATCHING_TAG you can't easy delete all cache items by only 'item_1' tag.

All of sub task and this issue is solved in SVN r12415

really good work !

Thank you ;-)

Changing issues in preparation for the 1.7.0 release.