ZF-3934: clean of Zend_Cache with File Backend does not work as expected
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:
$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
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)
It's a choice (because you can do AND and OR). If we choosed your solution, it would be impossible to make an AND