Hot answers tagged

40 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 ...
Brad Bell's user avatar
  • 67.3k
33 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 ...
Lindsey D's user avatar
  • 23.9k
11 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 %} // ...
Ben Wilkins's 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 %} ...
Lindsey D's user avatar
  • 23.9k
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 ...
Tim Everts's user avatar
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 ...
andrew.welch's user avatar
  • 11.4k
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/...
oncode's user avatar
  • 220
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.
Alex Mejias's 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"&...
André Elvan's user avatar
  • 7,278
6 votes

Resolving “Stuck” Background Tasks

If you want an even more user friendly way of doing it, install the Task Manager plugin by Bob Olde Hampsink, and you can do it from the Craft control panel.
André Elvan's user avatar
  • 7,278
6 votes
Accepted

Resolving “Stuck” Background Tasks

The easiest way is to use a GUI MySQL client to connect to the Craft database and edit the table directly. Popular ones include Navicat and Sequel Pro, but there is a good list here of options for ...
Brad Bell's user avatar
  • 67.3k
6 votes
Accepted

Good practice to "Clear Caches" before you "Backup Database"?

Is this helpful, or am I just being OCD? Completely OCD. :) The database backup class already excludes unnecessary tables like asset indexing data, sessions, template caches, etc. during a backup. ...
Brad Bell's user avatar
  • 67.3k
6 votes
Accepted

DeleteStaleTemplateCaches taking forever

This is a side-effect of Craft's amazing automagical cache system. :) Check out my answer on this question for an explanation of what happens. Regarding your question of how to fix this, part of the ...
André Elvan's user avatar
  • 7,278
6 votes

Force browser to download latest CSS file

I tend to use a config.php variable (called assetVersion) for the production site, and just generate a random value for the dev site using Twig's random function. Looks like this: <link rel="...
Ian Ebden's user avatar
  • 894
5 votes

Is it possible to cache variables using the {% cache %} tag?

You can accomplish this by using the set/endset tags to create a variable from the cached output: {% set finalVariable %} {% cache %} {# heavy lifting (like queries) here #} {# ...
Aaron Waldon's user avatar
5 votes
Accepted

How to omit certain tag from (% cache %)

Unfortunately, the vanilla {% cache %} tag doesn't have a way to escape or ignore certain content. The obvious workaround is to have more than one {% cache %} tag, where the content that shouldn't be ...
Mats Mikkel Rummelhoff's user avatar
5 votes
Accepted

How to cache a Guzzle Http request?

You can either cache it globally or in the session // your cache key $key = 'akey'; $cache = Craft::$app->getCache(); $value = $cache->get($key); // check if there is a valid value that is not ...
Robin Schambach's user avatar
4 votes

How do I cache with the ElementAPI plugin?

I was also very interested in this, so i forked the repo from theoplampert and added some extra features. You can find it here, https://github.com/jacobnijgh/ElementAPI. This fork allows you to not ...
Jacob's user avatar
  • 282
4 votes

Cache issues making site super slow in production but not in dev mode

For others that might be facing an issue similar to this – we found that our Craft site was gradually getting slower and slower over a period of several days, despite using the {% cache %} tag. When ...
Simon East's user avatar
4 votes
Accepted

Unable to create the cache directory

Yes, Craft still has its runtime caches for compiling Twig templates (as seen in your example) and such. Craft's template and partial cache is separate from Twig's own template compilation, if I'm not ...
Matt Stein's user avatar
  • 3,996
4 votes

General speed/performance on large Craft build

We are constantly seeing the deleting stale template cache timeout problem on our servers - try increasing the time PHP can execute for to something very long. It seems like clearing the caches counts ...
Matt Wilcox's user avatar
  • 3,149
4 votes
Accepted

Looping out a lot of entries.

There isn't really a good way to extract large chunks of Craft entries using the core features in Twig. Every entry you fetch is a EntryModel and those take up some memory due to relations and other ...
naboovalley's user avatar
  • 2,834
4 votes
Accepted

Prevent craftcms caching CMS page with dynamic template

The {% cache %} tag does not exclude dynamic data. What it does, is to basically make note of any element criteria (i.e. any code relating to pulling entries, categories, assets, tags or users) ...
Mats Mikkel Rummelhoff's user avatar
4 votes

Using CRSF, AJAX form posts, with a CDN

I don't think you can cache that, since the tag is run server-side and rendered with template output, and will be unique on every page load. If you have content that's unique on every page load, you'd ...
Ben Wilkins's user avatar
4 votes

Delete Stale Template Caches tasks much larger in Production than Staging

First, this is perfectly normal. :) Have a look at Brandons explanation here on how the cache tag works. If the element was added or modified, it queues up a new “Delete Stale Template Caches” ...
André Elvan's user avatar
  • 7,278
4 votes
Accepted

What's the difference between setting cache with {% header %} tag and {% cache %} tag?

The header tag sets an HTTP response header, which may be used to (among other things) tell the browser that the response content is "cacheable". The cache tag tells Craft to cache the generated HTML ...
Stephen Lewis's user avatar
4 votes
Accepted

Using cache tag on array outputs nothing

The {% cache %} tag is only designed to do one thing – to capture output (e.g. HTML) and store that output to the database, so that the next time Craft encounters that particular cache tag, it can ...
Mats Mikkel Rummelhoff's user avatar
4 votes
Accepted

Static page caching using Nginx FastCGI Cache with CraftCMS

The issue had something to do with PATH_INFO. Adding 'usePathInfo => true' in general.php fixed the issue. Here's the detailed explanation from Craft docs: https://craftcms.com/support/enable-path-...
Anya Dit's user avatar
  • 356
4 votes
Accepted

Craft incredibly slow site performance

It turned out this was the culprit. Craft was doing a deprecationerrors query (https://github.com/craftcms/cms/issues/2539). Turning devMode to false fixed this. Hope this helps someone...
Hassan Mahmood's user avatar
4 votes

Recommended caches to clear after server deployments?

I recommend clearing all caches on deploy via clear-caches/all. Caches should not be used to mask performance issues, they are used to solve concurrency & scaling, by holding onto data that doesn'...
andrew.welch's user avatar
  • 11.4k

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