Aug 12. 2018 · by Helge Sverre

How to disable template caching in dev mode

When actively working on a Craft site, having to clear the template cache manually is cumbersome, but you can disable the caching by using a simple if condition in your cache tag:

Cache example
TWIG
{% cache if not craft.app.config.general.devMode %}
    <!-- Stuff that will be cached here <-->
{% endcache %}

If you're using any other parameters with the cache tag, like "globally" or "using key 'some-key'", add the if condition at the end.

Cache example with options
TWIG
{% cache globally using key "footer" if not craft.app.config.general.devMode %}
    <!-- Stuff that will be cached here <-->
{% endcache %}

The code above is for Craft 3, if you want to achieve the same for Craft 2, replace craft.app.config.general.devMode with craft.config.devMode

References and links in this article