Hello I want to integrate the invalidation of cache of symfony but this one does not delete the cache I use memcached
In the repository I add the tags
$query = $this->getEntityManager()->createQuery($sql)->setParameters($params);
$cacheData = $cache->getItem(md5(serialize($query->getParameters())).$page);
if (!$cacheData->isHit()) {
$result = $query->setFirstResult(($page-1) * $maxPerPage)->setMaxResults($maxPerPage)
->useResultCache(true, 3000, md5(serialize($query->getParameters())).$page )
->useQueryCache(true)
->getResult();
$cacheData->set($result);
$cache->save($cacheData);
$cacheData->tag(['media', 'media_' . $category]);
} else {
$result = $cacheData->get();
}
When I add a data I empty the cache as if below but it does not empty
$cache = new TagAwareAdapter($this->get('cache.app'));
$cache->invalidateTags(['media']);
2
Answers
You saved it and assigned tag after that.
Try to tag it before saving.
In Symfony 3.4 I am currently using cache tag invalidation like so:
Cache service declaration
Controller
To expand; invalidating a cache tag does NOT delete the cache item from the caching service. It only increments the cache item version number, this causes additional references to the cache item to be a miss.
This is the intended functionality to avoid race conditions. [sic]
To remove it from the cache entirely you MUST use
$cache->deleteItem('user-test');