Issues

ZF-3934: clean of Zend_Cache with File Backend does not work as expected

Issue Type: Bug Created: 2008-08-12T12:47:57.000+0000 Last Updated: 2009-08-28T02:58:38.000+0000 Status: Resolved Fix version(s): Reporter: frank habermann (lordlamer) Assignee: Fabien MARTY (fab) Tags: - Zend_Cache

Related issues: Attachments:

Description

The clean function with CLEANING_MODE_MATCHING_TAG and CLEANING_MODE_NOT_:MATCHING_TAG with File Backend does not work as expected. I think i found a logical problem in this class.

Example:

<pre class="highlight">
$cache->save($huge_data, 'myUniqueID', array('tagA', 'tagB', 'tagC'));
$cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('tagX', 'tagC'));

My logic says that the cache wit id 'myUniqueID' should be cleared. But try it out. It will not be deleted If the first of the tags will not be found the hole entry will not be deleted in the backend.

So i changed the following here in file Zend/Cache/Backend/File.php from line 508 to 531

<pre class="highlight">
                    case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
                        $matching = false;
                        foreach ($tags as $tag) {
                            if (in_array($tag, $metadatas['tags'])) {
                                $matching = true;
                                break;
                            }
                        }
                        if ($matching) {
                            $result = ($result) && ($this->remove($id));
                        }
                        break;
                    case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
                        $matching = true;
                        foreach ($tags as $tag) {
                            if (in_array($tag, $metadatas['tags'])) {
                                $matching = false;
                                break;
                            }
                        }
                        if ($matching) {
                            $result = ($result) && $this->remove($id);
                        }                       
                        break;

After changing this the function works as expected.


a third parameter to the clean function would be fine to affect if AND or OR is used by CLEANING_MODE_MATCHING_TAG and CLEANING_MODE_NOT_MATCHING_TAG

Comments

Posted by Fabien MARTY (fab) on 2008-08-13T00:48:07.000+0000

No it works as expected

when you use "$cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('tagX', 'tagC'));" you want to clean cache records which are tagged with tagX AND tagC

if you want to clean cache records which are tagged with tagX OR tagC, you have to do (two lines)

<pre class="highlight">
"$cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('tagX')"; "$cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('tagC')";

It's a choice (because you can do AND and OR). If we choosed your solution, it would be impossible to make an AND

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