Clear by tags

@param  CachePoolInterface $cache
@param  string $tag tag
@return bool
@access public
424728
public function clearByTag(
        CachePoolInterface $cache,
        /*# string */ $tag
    )/*# : bool */ {
        // get tagItem for $tag
        $tagKey  = $this->getTagKey($tag);
        $tagItem = $cache->getItem($tagKey);

        // read array of keys from $tagItem
        if ($tagItem->isHit()) {
            $keyArray = $tagItem->get();
            foreach (array_keys($keyArray) as $key) {
                if ($cache->deleteItem($key)) {
                    unset($keyArray[$key]);
                }
            }

            // get error
            if (count($keyArray)) {
                $this->setError(
                    $cache->getError(),
                    $cache->getErrorCode()
                );
            }

            // update tagItem
            $tagItem->set($keyArray);
            $tagItem->expiresAfter($this->tag_life); // one year
            $cache->save($tagItem);

            if (count($keyArray)) {
                return false;
            }
        }

        return $this->trueAndFlushError();
    }
1361429
public function removeTag($tag)
    {
        if ($this->started !== true) {
            throw new Exception\SessionNotStartedException('Tried to tag a session which has not been started yet.', 1355150140);
        }
        $index = array_search($tag, $this->tags);
        if ($index !== false) {
            unset($this->tags[$index]);
        }
    }
904938
private function updateExpireTag($tag, $lifetime = null)
    {
        try {
            if (isset($this->_hashmap[$tag])) {
                foreach (array_keys($this->_hashmap[$tag]) as $key) {
                    $value = $this->load($key);
                    if ($value) {
                        $this->save($key, $value, $lifetime, $tag);
                    }
                }

                return true;
            }
        } catch (\Exception $e) {
            $this->log('warning', \sprintf('Unable to update cache ttl for tag %s : %s', $tag, $e->getMessage()));

            return false;
        }

        return false;
    }
1356217
def cache_invalidate_by_tags(tags, cache=None):
    
    if isinstance(tags, basestring):
        tags = [tags]
    tag_keys = [CACHE_TAG_KEY % tag for tag in tags if tag]
    if not tag_keys:
        raise ValueError('Attr tags invalid')
    if cache is None:
        cache = default_cache
    tag_keys_for_delete = []
    if cache.__class__.__name__ == 'RedisCache':
        from django_redis.exceptions import ConnectionInterrupted
        try:
            redis_client = cache.client.get_client()
            for tag_key in tag_keys:
                keys = redis_client.smembers(tag_key)
                if keys:
                    cache.delete_many(keys)
                    tag_keys_for_delete.append(tag_key)
        except ConnectionInterrupted:
            pass  # todo add logging
    else:
        for tag_key in tag_keys:
            keys = cache.get(tag_key)
            if keys:
                cache.delete_many(keys)
                tag_keys_for_delete.append(tag_key)
    if tag_keys_for_delete:
        cache.delete_many(tag_keys_for_delete)
1007616
public function purgeByTag($tags)
    {
        if (is_string($tags)) {
            $tags = [$tags];
        }

        // initialize log
        $log = new DebugLog();
        $log->addMessage('State', 'Purge by cache tag');

        // get caches from index storage
        $cacheKeys = $this->indexStorage->selectByTags($tags);
        if (!is_array($cacheKeys)) {
            return false;
        }

        foreach ($cacheKeys as $ck) {
            // purge from cache storage
            $this->cacheStorage->purge($ck);
        }

        // purge the index storage
        $this->indexStorage->deleteEntryByTags($tags);

        return true;
    }
462112
private function removeTag($tag)
    {
        try {
            if (isset($this->_hashmap[$tag])) {
                foreach (array_keys($this->_hashmap[$tag]) as $key) {
                    if (\apc_delete($key)) {
                        unset($this->_hashmap[$tag][$key]);
                    }
                }

                return $this->saveHashmap();
            }
        } catch (\Exception $e) {
            $this->log('warning', \sprintf('Unable to delete cache for tag %s : %s', $tag, $e->getMessage()));

            return false;
        }

        return true;
    }
291790
public function flush($tag)
    {
        if ($this->isTaggable()) {
            return Cache::tags($tag)->flush();
        }

        return Cache::flush();
    }
759260
public function removeTag($tag)
    {
        if ($this->started !== true) {
            throw new Exception\SessionNotStartedException('The session has not been started yet.', 1422551049);
        }
        if (isset($this->tags[$tag])) {
            unset($this->tags[$tag]);
        }
    }
59549
public function flushByTag(string $tag): int
    {
        $identifiers = $this->findIdentifiersByTag($tag);
        if (count($identifiers) === 0) {
            return 0;
        }

        foreach ($identifiers as $entryIdentifier) {
            $this->remove($entryIdentifier);
        }
        return count($identifiers);
    }
150556
public function deleteEntryByTags(array $tags)
    {
        foreach ($this->array['Key2Tags'] as $key => $keyTags) {
            $found = true;
            foreach ($tags as $t) {
                if (!array_search($t, $keyTags)) {
                    $found = false;
                }
            }

            if ($found) {
                $this->deleteEntryByKey($key);
            }
        }
    }
117420
public function removeListenersWithTag($tag)
    {
        foreach ($this->listeners as $event => $priorities) {
            $this->clearSortedListeners($event);
            foreach ($priorities as $priority => $listeners) {
                $this->listeners[$event][$priority] = array_filter($listeners, function (TaggableListenerInterface $listener) use ($tag) {
                    return $listener->getTag() !== $tag;
                });
            }
        }

        return $this;
    }
381418
protected static function removeFragment($template, $tag)
    {
        $fragment = self::fetchFragment($template, $tag);

        return !empty($fragment) ? str_replace($fragment, '', $template) : $template;
    }
1073833
public function removeByTag($tag)
    {
        $tags = (is_array($tag) ? $tag : array($tag));
        try {
            foreach ($tags as $tag) {
                $this->removeTag($tag);
            }
        } catch (\Exception $e) {
            $this->log('warning', \sprintf('Unable to delete cache for tag(s) %s : %s', \implode(',', $tags), $e->getMessage()));

            return false;
        }

        return true;
    }
197089
public function deleteMatchingAllTags(array $tags)
    {
        $this->collection->batchDelete(function (\Sokil\Mongo\Expression $e) use ($tags) {
            return $e->whereAll(Cache::FIELD_NAME_TAGS, $tags);
        });
        
        return $this;
    }
1350222
protected function invalidateCache(array $tags, $time = null)
    {
        if ($this->_cache) {
            $this->_cache->invalidateTags($tags, $time);
        }

        return $this;
    }
231801
public function clear(): bool
    {
        if (!empty($this->tag)) {
            foreach ($this->tag as $tag) {
                $this->clearTag($tag);
            }
            return true;
        }

        $this->writeTimes++;
        return wincache_ucache_clear();
    }
316624
public function flush($tag = null)
    {
        if (! $this->cacheIsTaggable) {
            throw new MethodNotSupportedException('The cache driver ('.
                get_class($this->cacheManager->driver()).') doesn\'t support the flush method.');
        }

        $tag = $tag ?: $this->cacheKey;
        $this->cache->tags($tag)->flush();
    }