Pimcore\Cache::clearTags PHP Method

clearTags() public static method

Removes entries from the cache matching the given tags
public static clearTags ( array $tags = [] ) : void
$tags array
return void
    public static function clearTags($tags = [])
    {
        // do not disable clearing, it's better purging items here than having inconsistent data because of wrong usage
        /*if (!self::$enabled) {
              Logger::debug("Cache is not cleared because it is disabled");
              return;
          }*/
        self::setWriteLock();
        Logger::info("clear cache tags: " . implode(",", $tags));
        // ensure that every tag is unique
        $tags = array_unique($tags);
        // check for ignored tags
        foreach (self::$ignoredTagsOnClear as $t) {
            $tagPosition = array_search($t, $tags);
            if ($tagPosition !== false) {
                array_splice($tags, $tagPosition, 1);
            }
        }
        // check for the tag output, because items with this tags are only cleared after the process is finished
        // the reason is that eg. long running importers will clean the output-cache on every save/update, that's not necessary,
        // only cleaning the output-cache on shutdown should be enough
        $outputTagPosition = array_search("output", $tags);
        if ($outputTagPosition !== false) {
            array_splice($tags, $outputTagPosition, 1);
            self::addClearTagOnShutdown("output");
        }
        // add tag to clear stack
        foreach ($tags as $tag) {
            self::$clearedTagsStack[] = $tag;
        }
        // clean tags, except output
        if ($cache = self::getInstance()) {
            $cache->clean(\Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, $tags);
        }
    }

Usage Example

Ejemplo n.º 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($input->getOption("tags")) {
         $tags = explode(",", $input->getOption("tags"));
         Cache::clearTags($tags);
     } elseif ($input->getOption("output")) {
         Cache::clearTag("output");
     } else {
         Cache::clearAll();
     }
 }
All Usage Examples Of Pimcore\Cache::clearTags