What are the best practices for using the {% cache %} tag? I started using the {% cache %} tag and would like to know what the best practices are:

.

Regarding performance:

For example does it make sense..


..to cache the whole template, or is it better to enclose each query separately?
..to combine the cache-tag with other supported caches?
..to cache non-dynamic content?


.

Regarding development:

I saw the tip to use: {% cache unless craft.config.devMode﻿ %}. Is there anything else to consider during development?
Generally you’ll just want to cache areas of your templates that are going to trigger a lot of database queries, or fetch a lot of data, since those are going to have the biggest hit on your site’s performance. Matrix field loops that have relationship fields inside them (Entries/Assets/etc.) are a good example, since each Matrix block is going to come with one or more DB queries.

There’s not much advantage to caching less intensive areas of your templates, and might lead to unexpected consequences, if you have anything dynamic being output that’s not pure-content, such as the logged in user’s username.


  ..to combine the cache-tag with other supported caches?


Worth mentioning that template caching does not respect the cacheMethod setting – that’s just for data caches. Template caches always go to the database, which in this case is the most performant option.