Pimcore\Cache\Backend\Memcached::clean PHP Метод

clean() публичный Метод

Available modes are : 'all' (default) => remove all cache entries ($tags is not used) 'old' => remove too old cache entries ($tags is not used) 'matchingTag' => remove cache entries matching all given tags ($tags can be an array of strings or a single string) 'notMatchingTag' => remove cache entries not matching one of the given tags ($tags can be an array of strings or a single string)
public clean ( string $mode = Zend_Cache::CLEANING_MODE_ALL, array $tags = [] ) : boolean
$mode string Clean mode
$tags array Array of tags
Результат boolean True if no problem
    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;
    }