I'm trying to disable template caching in my development environment. I've tried a few things but thus far nothing has worked. I had thought that just setting devMode to true in the config would do the trick, but I'm still caching. The control panel shows the caution lines to indicate I'm in dev mode, but I still have to manually clear the cache before template changes show up. What am I overlooking?
It is true that devMode does not turn off caching. What I do is define a flag in general.php:
'cacheThings' => true, // true by default, but usually false for dev
and then in my templates:
{% cache if craft.config.cacheThings %}
update
Since version 2.4 there is a new config value: enableTemplateCaching, so all you need to do now is set this false
in your development environment.
-
This workaround is fine and it's good that devMode doesn't automatically disable the cache, but in my opinion there really should be a config setting for disabling the cache completely. I just added a feature request here: feedback.buildwithcraft.com/forums/285221-feature-requests/… – Mats Mikkel Rummelhoff Apr 16 '15 at 10:30
Not that creating an additional variable is that much effort, but since I only want to not cache if in devMode
, I based my solution on Marion's utilizing the same devMode
variable I'm using elsewhere.
{% cache if not craft.config.devMode %}
-
For Craft 3 this need to be: {% cache if not craft.app.config.general.devMode %} – portnull Jan 15 '20 at 10:50