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 ...
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 ...
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 %}
// ...
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 %}
...
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 ...
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 ...
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/...
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.
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"&...
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.
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 ...
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.
...
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 ...
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="...
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 #}
{# ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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) ...
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 ...
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” ...
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 ...
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 ...
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-...
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...
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'...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
cache × 271templating × 32
performance × 24
craft3 × 23
plugin-development × 21
assets × 8
database × 8
craft2 × 8
tasks × 8
redis × 7
config × 6
plugin-elementapi × 6
error × 6
filecache × 6
control-panel × 5
php × 5
pagination × 5
nginx × 5
image-transforms × 4
variable × 4
server × 4
csrf × 4
speed × 4
plugin-blitz × 4
entries × 3