I’m using the twig cache in a Symfony 5.4 project. If I cache something like:
{% cache "customer_1" ttl(3600) tags('customer') %}
Some HTML here
{% endcache %}
I need to be able to invalidate the twig cache with tag "customer" from within a Symfony controller or service. I’ve tried autoloading SymfonyContractsCacheTagAwareCacheInterface $twigCache
(found from bin/console debug:autowiring
) but this doesn’t seem to work – called $twigCache->invalidateTags(['customer'])
does nothing.
Is it possible to access and clear the twig cache from the Symfony side?
2
Answers
You could try this command, it clears all the cache inside the cache directory.
Let me now if it works for you.
to clear indivduel tags you can use:
bin/console cache:pool:invalidate-tags
this uses the exact same command (
$pool->invalidateTags($tags)
) you tried to use. so it should work.see
vendor/symfony/framework-bundle/Command/CachePoolInvalidateTagsCommand.php