Issues

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

Issue Type: Bug Created: 2011-10-20T08:57:43.000+0000 Last Updated: 2011-11-03T08:46:42.000+0000 Status: Open Fix version(s): Reporter: Janos Thiele (janos) Assignee: Alexander Veremyev (alexander) Tags: - Zend_Cache

  • cache

Related issues: Attachments:

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

Posted by Janos Thiele (janos) on 2011-10-20T09:05:49.000+0000

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

<pre class="highlight">

            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;

Posted by Adam Lundrigan (adamlundrigan) on 2011-10-28T15:39:51.000+0000

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.

Posted by Janos Thiele (janos) on 2011-11-03T08:46:42.000+0000

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}

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts