Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

Hot answers tagged

39 votes
Accepted

What are the best practices for using the {% cache %} tag?

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 ...
user avatar
38 votes
Accepted

What are the cache options available to a Craft installation?

There are many different caching levels on a web server, some of them are Craft-specific, and some have nothing to do with Craft, but they often get confused. In addition to that, some of them you ...
user avatar
  • 66.4k
37 votes
Accepted

Generating pending image transforms stuck in process

More of a "How do I debug stuck tasks" answer, but it should help you. Open up your craft_tasks table. You'll see one task in with a 'status' of 'running' and if you refresh the table several times, ...
user avatar
  • 66.4k
32 votes

Can I disable template caching for local development?

As of Craft 2.4, it is now possible to use the enableTemplateCaching config value. 'enableTemplateCaching' => false, Simply add that to your local environment in config/general.php, and it'll ...
user avatar
  • 23.6k
31 votes

What are the best practices for using the {% cache %} tag?

When working with multiple environments you likely want to disable caching for all but one environment, because Craft saves the absolute url to entries/assets in the cache. I achieved this by ...
user avatar
  • 35.8k
18 votes
Accepted

Can I disable template caching for local development?

When working with multiple environments you most likely want to disable caching for all but one environment, because Craft saves the absolute URL to entries/assets in the cache. I achieved this by ...
user avatar
  • 35.8k
18 votes
Accepted

Is there a way to force Assets to redo transforms?

I can't actually reproduce your problem but here's a couple of things to check and try: Clear your browsers cache! Did you re-upload through Assets with the same filename and click replace? Purge all ...
user avatar
  • 2,301
18 votes
Accepted

Adding active class to globally cached navigation

Yes, you can! The first thing you need to do is to add the entire cached content into a single variable: {% set navigation %} {% cache globally for 3 years %} {# YOUR CACHED CONTENT #} ...
user avatar
  • 2,824
12 votes
Accepted

Caching not working on page with asynchronously loaded asset transforms

Seems to be the case that Craft won't attempt to resolve these /cpresources/transforms/ URLs until the asset is actually requested, which can mess with a setup like PictureFill where there is no ...
user avatar
  • 815
12 votes
Accepted

Why does my base template never reload?

Are you using PHP 5.5? If so, opCache is enabled by default and that’s probably causing your issue.
user avatar
  • 66.4k
10 votes
Accepted

Why does Craft set no-cache headers for all requests?

Craft doesn't explicitly set any caching headers in the response, but you can control exactly how you want your caching headers to behave from your templates with the {% header %} tag. For example: {...
user avatar
  • 66.4k
10 votes
Accepted

Varnish 4.x and Craft

I'm by no means a Varnish pro, but I'm currently working on a project where we're running Varnish 4.0 in front of our nginx servers. I've uploaded an example of our VCL 4.0 file in this gist. It is ...
user avatar
  • 7,228
10 votes
Accepted

Troubleshooting paginated content cached globally

I ran into this today. I thought craft.request.path used to include the pagination page number but it doesn't appear to anymore. Maybe it was always like this though. Regardless, this is how I'm now ...
user avatar
10 votes
Accepted

How can I Prevent CSRF Tokens from being Cached?

You can do something like this: // First, set all your cached content to a variable: {% set myContent %} {% cache %} {# YOUR CACHED CONTENT #} %%MY_CSRF%% {% endcache %} {% endset %} // ...
user avatar
9 votes

How can I Prevent CSRF Tokens from being Cached?

The trick is to inject the CSRF field using JavaScript. Omit the standard getCsrfInput Twig tag. Give your form(s) the class of csrf. Add this Twig code outside of the cached area: {% includejs %} ...
user avatar
  • 23.6k
8 votes

Why does my base template never reload?

For those interested: Disabling opCache in Mamp: Go to: /Applications/MAMP/bin/php/php5.5.3/conf/php.ini. OP Cache is at the bottom of the file. Comment out the following lines with a semicolon ;: ...
user avatar
  • 3,664
8 votes
Accepted

Long 'Deleting stale template caches'

The {% cache %}, by default will cache it's contents on a per URL and per locale basis. A lot of times when we see the behavior you're seeing, that's not the desired behavior and you should be using ...
user avatar
  • 66.4k
8 votes

Cache tag won’t cache in a template

The {% cache %} tag will detect if there are any ungenerated image transforms within it. If there are, it will hold off on caching the template until the next request, so that the temporary image URL ...
user avatar
8 votes
Accepted

Adding cache headers to Nginx configuation file breaks the /admin area

Craft rewrites the location of those files using a query string, which is what's causing nginx to lose track of them. Using the try_files directive should force nginx to find and serve them properly. ...
user avatar
8 votes
Accepted

Cacheing in PHP code for plugin

You want to take a look at the CacheService class which is the service that allows you to programmatically interact with the internal cache. This is an example of how to set some cache that expires ...
user avatar
8 votes
Accepted

How to disable template caching? devMode isn't doing it

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: {% ...
user avatar
8 votes
Accepted

Are there any file-based static cache options for Craft CMS?

Someone has recently developed a standalone static HTML caching plugin for Craft CMS which does similar to what you're after: HTML Cache plugin for Craft CMS This Craft plugin will generate static ...
user avatar
8 votes
Accepted

How do I cache with the ElementAPI plugin?

The ElementAPI plugin itself doesn't seem to offer a caching solution, but there is a fork from a guy which has implemented a caching option cache and cacheTime: https://github.com/theolampert/...
user avatar
  • 220
8 votes
Accepted

Caching queries not working as expected

The {% cache %} tag only caches the HTML output. That's it. In your example above, nothing is cached, and categoryProducts will be an empty set. One thing you could do is to cache each entry ...
user avatar
  • 10.9k
7 votes
Accepted

Is it possible to clear caches and re-index assets programattically?

I guess it depends. So, behind the scenes, Craft can have different cache drivers. You might use the db or file cache, or something like Redis or Memcache. Took a peek at ClearCachesTool, and it ...
user avatar
  • 2,947
7 votes
Accepted

Does the cache tag behave differently for Mobile vs Tablet vs Desktop?

Craft makes no distinction whether it's caching for mobile, tablet, desktop, etc., so it'll need to be taken care of on the template end. You can easily do that with the "using key" parameter of the {...
user avatar
  • 66.4k
7 votes
Accepted

Cache/ColdCache & checking for ungenerated image transforms

Set generateTransformsBeforePageLoad in your config/general.php file. 'generateTransformsBeforePageLoad' => true, Configures Craft to generate new image transforms right when getUrl() is called,...
user avatar
7 votes
Accepted

Section Single Title Caching

For anyone stuck on this -- when changing a Section's name you have to goto the entry under Entries and hit save. This will update the mysql row / title.
user avatar
7 votes
Accepted

Force browser to download latest CSS file

There are several plugins that can do this. With my plugin Stamp, you can add a timestamp to the filename or path in the following formats: <script src="/assets/build/js/1399647655/scripts.js"&...
user avatar
  • 7,228
6 votes
Accepted

Can Craft handle thousands of entries and high traffic?

Sure... we've seen Craft installs with several hundred thousands entries/users/assets/etc. running in the wild, but there really isn't a simple answer to this question. As you pointed out, ...
user avatar
  • 66.4k

Only top scored, non community-wiki answers of a minimum length are eligible