public function clean($mode = \Zend_Cache::CLEANING_MODE_ALL, $tags = [])
{
$this->checkCacheConsistency();
if ($mode == \Zend_Cache::CLEANING_MODE_ALL) {
$this->clearTags();
return $this->_memcache->flush();
}
if ($mode == \Zend_Cache::CLEANING_MODE_OLD) {
Logger::debug("Zend_Cache_Backend_Memcached::clean() : CLEANING_MODE_OLD is unsupported by the Memcached backend");
}
if ($mode == \Zend_Cache::CLEANING_MODE_MATCHING_TAG || $mode == \Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG) {
foreach ($tags as $tag) {
$items = $this->getItemsByTag($tag);
$quotedIds = [];
foreach ($items as $item) {
// We call delete directly here because the ID in the cache is already specific for this site
if ($this->remove($item, true)) {
$quotedIds[] = $this->getDb()->quote($item);
}
}
if (count($quotedIds) > 0) {
$this->getDb()->delete("cache_tags", "id IN (" . implode(",", $quotedIds) . ")");
}
}
}
if ($mode == \Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG) {
$condParts = ["1=1"];
foreach ($tags as $tag) {
$condParts[] = "tag != '" . $tag . "'";
}
$itemIds = $this->getDb()->fetchCol("SELECT id FROM cache_tags WHERE " . implode(" AND ", $condParts));
foreach ($itemIds as $item) {
$this->remove($item);
}
}
// insert dummy for the consistency check
try {
$this->getDb()->insertOrUpdate("cache_tags", ["id" => "___consistency_check___", "tag" => "___consistency_check___"]);
} catch (\Exception $e) {
// doesn't matter as long as the item exists
}
return true;
}