Conditional Cacheing in Craft.

,
Looks like this article is pretty old. Some of the information and/or techniques may now be obselete. Just sayin’
Conditional Cacheing in Craft on DesignKarma

Cacheing in Craft can improve performance for subsequent requests, as they will have less work to do, which is nice. Trouble is, if you're working locally the cache can sometimes get in the way – especially if you've spent the last 15 minutes trying to figure out why your changes aren't showing... er, for example.

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.

Let us help tell your story.

Ready to inject some karma into your project?

Get started