ZF-11833: Backend Static Cache clean method do not support the Zend_Cache::CLEANING_MODE_MATCHING_TAG mode

Description

Zend_Cache_Backend_Static::clean() does not implement the option Zend_Cache::CLEANING_MODE_MATCHING_TAG.

In this case the implementation from CLEANING_MODE_MATCHING_ANY_TAG is used. Which issn't the same! CLEANING_MODE_MATCHING_TAG: Should be used for an "and" conitioning of given tags. CLEANING_MODE_MATCHING_ANY_TAG: Should be used for an "or" conitioning of given tags.

Comments

The solution for me was to implement the case case Zend_Cache::CLEANING_MODE_MATCHING_TAG:



            case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
                
                if (empty($tags)) {
                    throw new Zend_Exception('Cannot use tag matching modes as no tags were defined');
                }
                
                if ($this->_tagged === null && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) {
                    $this->_tagged = $tagged;
                } elseif (!$this->_tagged) {
                    return true;
                }
                
                $urls = array_keys($this->_tagged);
                foreach ($urls as $url) {
                    if (isset($this->_tagged[$url]['tags'])) {

                        $count = 0;
                        
                        foreach ($tags as $tag) {
                            if (in_array($tag, $this->_tagged[$url]['tags'])) {
                                $count++;
                            }
                        }
                        
                        if ($count == count($tags)) {
                            $this->remove($url);
                            unset($this->_tagged[$url]);
                        }
                    }
                }
                
                $this->getInnerCache()->save($this->_tagged, self::INNER_CACHE_NAME);
                $result = true;
                break;

Can this change be safely implemented without breaking backwards-compatibility? Any code in the wild using {{Zend_Cache::CLEANING_MODE_MATCHING_TAG}} will behave differently than the original developer expected if this cleaning mode is (re-)implemented properly.

I guess so. Otherwise the developers has sed the Zend_Cache::CLEANING_MODE_MATCHING_TAG in the worng way!?

The documentation clearly says: {quote}If you want to remove cache entries matching the tags 'tagA' and 'tagC':

$cache->clean(
    Zend_Cache::CLEANING_MODE_MATCHING_TAG,
    array('tagA', 'tagC')
);{quote}

and

{quote} If you want to remove cache entries matching the tags 'tagA' or 'tagC':

$cache->clean(
    Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG,
    array('tagA', 'tagC')
);

{quote}