skip to Main Content

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


  1. You could try this command, it clears all the cache inside the cache directory.

    php bin/console cache:clear
    

    Let me now if it works for you.

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search