/** * @param array $tags * @param bool $intersectionOnly */ public function cleanByTags(array $tags, $intersectionOnly = false) { if (count($tags) === 1) { $intersectionOnly = false; } $tagsToCheck = $tagsWildcardToCheck = array(); foreach ($tags as $tag => $conf) { $tagMatched = false; if ($conf['type'] === self::WILDCARD_COMPARISON) { $tagContainerKey = $this->formatTagKey($tag, ''); $item = $this->createItem($tagContainerKey); $keys = unserialize($this->cacheAdapter->get($item)); if (empty($keys)) { $keys = array(); } foreach ($keys as $key) { if (preg_match('#.*' . $this->formatTagKey($tag, $conf['value']) . '.*#', $key)) { $tagsWildcardToCheck[$key] = $key; $tagMatched = true; } } } if (!$tagMatched) { $key = $this->formatTagKey($tag, $conf['value']); $tagsToCheck[$key] = $key; } } $wildcardKeys = $this->getKeysByTags($tagsWildcardToCheck, false); $strictKeys = $this->getKeysByTags($tagsToCheck, $intersectionOnly); if ($intersectionOnly && !empty($wildcardKeys)) { $keysToRemove = array_intersect($strictKeys, $wildcardKeys); } else { $keysToRemove = array_merge($strictKeys, $wildcardKeys); } foreach ($keysToRemove as $key) { $this->cacheAdapter->remove($this->createItem($key)); } }
/** * Remove a value from cache * * @param \Itkg\Core\CacheableInterface $item * @return void */ public function remove(CacheableInterface $item) { parent::remove($item); $this->adapter->remove($item); }
/** * Remove entity cache * * @param CacheEvent $event * * @return void */ public function removeEntityCache(CacheEvent $event) { $this->cache->remove($event->getCacheableData()); }