Conditional Cacheing in Craft

ian@designkarma.co.uk

Ian Ebden · September 1, 2015


Looks like this article was written a while ago. Some of the ideas and/or techniques described may now be obselete.

Fear not. There's a simple solution thanks to Craft's devMode config setting. Using a cache unless tag in your templates will mean stuff will only cache on the production site, not you local or staging instances.

{% cache for 1 month unless craft.config.devMode %}

The more I work with Craft the more I find simple one-line solutions to everyday issues.

By the way, if you're new to Craft's {% cache %} tag be sure to thoroughly read through the docs, as cacheing is not always necessary, nor is it always the answer to performance problems.