The Craft {% cache %} Tag In-Depth
Tags: cache, webperf, craftcms
Published: 2020-02-21 01:46:11

---
title: The Craft {% cache %} Tag In-Depth
published: true
date: 2016-11-30 09:47:00 UTC
tags: cache,webperf,craftcms
canonical_url: https://nystudio107.com/blog/the-craft-cache-tag-in-depth
---

# The Craft `{% cache %}` Tag In-Depth

### Craft CMS has a `{% cache %}` tag that can help with per­for­mance, if used effec­tive­ly. Here’s how it works.

Andrew Welch / [nystudio107](https://nystudio107.com)

![Craft Cms Cache Tag](https://nystudio107-ems2qegf7x6qiqq.netdna-ssl.com/img/blog/_1200x675_crop_center-center_82_line/craft-cms-cache-tag.jpg)

**Update:** This arti­cle has been updat­ed to cov­er both Craft CMS 2.x and Craft CMS 3.x

The <kbd>`{% cache %}`</kbd> tag avail­able in Craft CMS can help with per­for­mance, if you under­stand it and apply it cor­rect­ly. How­ev­er, as so elo­quent­ly stat­ed on the [Craft CMS Tem­plat­ing Docs](https://craftcms.com/docs/templating/cache) page:

<aside>
                                If you’re suf­fer­ing from abnor­mal page load times, you may be expe­ri­enc­ing a sub­op­ti­mal host­ing envi­ron­ment. Please con­sult a spe­cial­ist before try­ing `{% cache %}`. `{% cache %}` is not a sub­sti­tute for fast data­base con­nec­tions, effi­cient tem­plates, or mod­er­ate query counts. Pos­si­ble side effects include stale con­tent, exces­sive­ly long-run­ning back­ground tasks, stuck tasks, and in rare cas­es, death. Ask your host­ing provider if `{% cache %}` is right for you.
                            </aside>

In oth­er words, the <kbd>`{% cache %}`</kbd> tag is not some­thing you should use to mask per­for­mance prob­lems, be they from an ane­mic or poor­ly con­fig­ured serv­er, or tem­plates that are writ­ten inef­fi­cient­ly. You can’t just write hor­ri­bly inef­fi­cient tem­plates, slap them up on GoDad­dy shared host­ing, and expect to ​“solve” the per­for­mance prob­lems with the <kbd>`{% cache %}`</kbd> tag. We call that putting lip­stick on a pig.

How­ev­er, it can be an extreme­ly use­ful tool once you under­stand what it is, and how to uti­lize it.

## Why Do We Cache?

The gen­er­al idea behind a cache is that we want to keep data that we access fre­quent­ly around in a for­mat that can quick­ly be retrieved. We do this in our dai­ly lives, too. When you wake up in the morn­ing and open up the med­i­cine cab­i­net, every­thing you need to get ready is right there wait­ing for you.

Imag­ine how much time it would take you to get ready in the morn­ing if your toi­letries were scat­tered all over your house, and you had to hunt for them every morning…

We are _pre­flight­ing_ our morn­ing rou­tine by _caching_ the stuff we need all in one place, so we can get our job of get­ting ready done efficiently.

And that’s exact­ly why we cache data on our com­put­ers as well. Rather than com­pute some insane­ly com­pli­cat­ed for­mu­la pulled from a mas­sive dataset each time a web­page is loaded, we can cache it. We cal­cu­late the result at a non-crit­i­cal time, and present this cached result to the user when they load the page.

Every­one’s happy.

## What Exact­ly Does the `{% cache %}` Tag Do?

So now that we under­stand why we want to cache data, let’s have a look at exact­ly how the <kbd>`{% cache %}`</kbd> tag in Craft CMS works. Here’s a pret­ty stan­dard chunk of Twig code:

```

{% for entry in craft.entries.section('blog').relatedTo(someCategory) %}
    <article>
        <h1>{{ entry.title }}</h1>
        <p>{{ entry.summary }}</p>
        <img src="{{ entry.image.first().getUrl(myTransform) }}">
    </article>
{% endfor %}

```

This code gen­er­ates a num­ber of data­base queries to pull in all of our <kbd>blog</kbd> entries that are relat­ed to <kbd>someCategory</kbd> and then loops through and dis­plays them. The <kbd>`{{ entry.image.first().getUrl(myTransform) }}`</kbd> actu­al­ly gen­er­ates sev­er­al data­base queries each time through the loop, because Assets are rela­tions that need to be looked up, and it has to look up the Asset trans­form. This is called the N+1 query prob­lem, and it basi­cal­ly just means that the more entries we have, the slow­er things are gonna get.

Do we real­ly need to do all of these data­base queries every time some­one loads our web page? Nope. We only post a new blog entry once a week at best; there’s no rea­son to do all of these data­base queries every sin­gle time a page is loaded.

So instead, we can wrap it in a <kbd>`{% cache %}`</kbd> tag:

```

{% cache %}
    {% for entry in craft.entries.section('blog').relatedTo(someCategory) %}
        <article>
            <h1>{{ entry.title }}</h1>
            <p>{{ entry.summary }}</p>
            <img src="{{ entry.image.first().getUrl(myTransform) }}">
        </article>
    {% endfor %}
{% endcache %}

```

All that the <kbd>`{% cache %}`</kbd> tag does is cap­ture the parsed out­put of what­ev­er it’s wrapped around, and stores the result as text in the data­base. So instead of a bunch of queries for our entries, and a num­ber of queries for our <kbd>entry.image.first().getUrl(myTransform)</kbd> each time through the loop, we only end up with one query for our cached result.

This is why we want to use <kbd>`{% cache %}`</kbd> tags around blocks of Twig code that are either com­pute-inten­sive, or blocks of Twig code that gen­er­ate a large num­ber of data­base queries. If you just wrap plain old HTML text in <kbd>`{% cache %}`</kbd> tags, you won’t see any gains. It might even be ever so slight­ly slow­er, because we’ve added a data­base query where before there was none.

_Tan­gent:_ Astute read­ers will note that the above exam­ple is a per­fect can­di­date for [Eager Load­ing](https://craftcms.com/docs/templating/eager-loading-elements), but that’s beyond the scope of this article.

If you have <kbd>devMode</kbd> enabled, you can view your JavaScript Con­sole to see the num­ber of data­base queries exe­cut­ed on a page. Here’s what it looks like for this blog page you’re read­ing right now, with­out <kbd>`{% cache %}`</kbd> tags:

![Caching Off](https://nystudio107-ems2qegf7x6qiqq.netdna-ssl.com/img/blog/_768x226_crop_center-center_100_line/caching_off.png)

And here’s what the same blog page looks like with <kbd>`{% cache %}`</kbd> tags judi­cious­ly used:

![Caching On](https://nystudio107-ems2qegf7x6qiqq.netdna-ssl.com/img/blog/_768x226_crop_center-center_100_line/caching_on.png)

We went from <kbd>102</kbd> data­base queries down to <kbd>43</kbd> data­base queries, and the time these queries took went from <kbd>1.84s</kbd> down to just <kbd>0.49s</kbd>! This is a huge gain, for very lit­tle work! And the num­ber of queries for the page with­out <kbd>`{% cache %}`</kbd> tags will keep going up as we add more blog entries, while the num­ber of queries for our cached page will stay con­stant. We have sub­sti­tut­ed many data­base queries for few­er, which results in bet­ter performance.

The key take-away here is that what the <kbd>`{% cache %}`</kbd> tag is doing is stor­ing the parsed out­put of the Twig code that’s inside of it. If you have Twig code such as <kbd>`{{ now|date("M d, Y") }}`</kbd> inside a <kbd>`{% cache %}`</kbd> tag, what’s saved in the cache is not the Twig code, but rather the parsed result (in this case, a date). So the date dis­played on the web­page is not going to change as long as the data is cached.

So if our code is:

```

{% cache %}
    {{ now|date("M d, Y") }}
{% endcache %}

```

What’s actu­al­ly saved in the data­base for this cached chunk of Twig code is just:

```

Nov 30, 2016

```

_Tan­gent:_ The <kbd>cacheDuration</kbd> [Gen­er­al Con­fig Set­ting](https://craftcms.com/docs/config-settings) deter­mines how long a tem­plate cache will be kept around. This set­ting defaults to <kbd>P1D</kbd> (1 day, or 24 hours), which means that your caches are going to be regen­er­at­ed every 24 hours. While this is a sen­si­ble default set­ting, it is a bit con­ser­v­a­tive, giv­en Craft’s auto­mat­ic cache break­ing. I typ­i­cal­ly set it to <kbd>cacheDuration =&gt; false</kbd> in my <kbd>craft/config/general.php</kbd> file, which means that the tem­plate caches _nev­er_ expire on their own, they only are regen­er­at­ed when con­tent inside the <kbd>`{% cache %}`</kbd> tags changes. For a dis­cus­sion of how to use mul­ti-envi­ron­ment con­fig set­tings, check out the [Mul­ti-Envi­ron­ment Con­fig for Craft CMS](https://nystudio107.com/blog/multi-environment-config-for-craft-cms) article.

## Cache-Busters!

That brings up an inter­est­ing conun­drum. What hap­pens if some­one changes one of the blog entries that was inside of our <kbd>`{% cache %}`</kbd> tags? Craft is actu­al­ly pret­ty clever about it: it keeps track of any _ele­ments_ (entries, assets, etc.) that are inside of your <kbd>`{% cache %}`</kbd> tags, and will mark the cache as being stale if they have changed. So it will auto­mat­i­cal­ly break the cache for you, caus­ing it to regen­er­ate and re-cache the data.

This is great, but we also have to do our jobs being smart about what we cache, and how we cache it. For exam­ple, a typ­i­cal blog page will have the blog entry itself, as well as a ​“blog archives” sec­tion that lists all of our old­er blog entries.

Now, we could just wrap the entire tem­plate in <kbd>`{% cache %}`</kbd> tags and call it a day. How­ev­er, think about what hap­pens when a new blog is pub­lished: it will inval­i­date every sin­gle blog page cache, because our archives changed with the addi­tion of a new blog post! This seems a bit sil­ly, because our oth­er blogs entries did­n’t change at all. All that changed was our blog archives sec­tion, to list the new blog entry.

If you think about it from an abstract point of view, we real­ly have two enti­ties we want to cache in this case:

1. The blog entry itself
2. The blog archives

Because they real­ly are inde­pen­dent of each oth­er. We might add a new blog post that would cause the blog archives to need to change, but this does­n’t affect our each blog entry.

Fur­ther, every sin­gle blog entry page is going to share the same exact blog archives sec­tion. So, we can do some­thing like this:

## Craft 2.x Example

This is an exam­ple that cov­ers **Craft 2.x** specif­i­cal­ly; although most of the code is sim­i­lar for Craft 3.x, the way the default cache key is deter­mined is different.

```

{# -- Our blog entry -- #}
{% cache globally using key craft.request.path %}
    <article>
        <h1>{{ entry.title }}</h1>
        <p>{{ entry.body }}</p>
        <img src="{{ entry.image.first().getUrl(myTransform) }}">
    </article>
{% endcache %}

{# -- Our blog archives -- #}
{% cache globally using key "blog-archives" %}
    <section>
        {% for blogArchive in craft.entries.section('blog') %}
            <h1>{{ blogArchive.title }}</h1>
            <p>{{ blogArchive.summary }}</p>
        {% endfor %}
    </section>
{% endcache %}

```

Here we have two sep­a­rate caches on one page. The first is for our actu­al blog entry; the sec­ond is a _glob­al­ly_ cached out­put of our blog archives, stored in the data­base as <kbd>blog-archives</kbd>. This means that there is a unique cache of each blog entry, but a sin­gle _glob­al­ly_ shared cache of our blog archives.

Which is great, because we don’t want every sin­gle blog page to have to be re-cached when­ev­er we add a new blog entry. It’ll just re-cache the blog archives cache, which all of our blog pages share.

You’ll also notice that instead of just using the <kbd>`{% cache %}`</kbd> tag on its own, we’re actu­al­ly using <kbd>`{% cache globally using key craft.request.path %}`</kbd>. We do this because the default behav­ior for the <kbd>`{% cache %}`</kbd> tag is to use the _full path_ as a way of unique­ly iden­ti­fy­ing our cache (in addi­tion to a unique hash that Craft auto­mat­i­cal­ly gen­er­ates, so we can have more than one <kbd>`{% cache %}`</kbd> tag per page). This full path _includes the query string,_ which is any­thing after the ? in a URI, e.g.: <kbd>?utm_source=GHDJ14J</kbd>.

But we don’t real­ly want the query string to cause a new, unique cached item, oth­er­wise we could poten­tial­ly end up with hun­dreds or even thou­sands of entries in the <kbd>craft_templatecaches</kbd> data­base table. For instance, if we just use the <kbd>`{% cache %}`</kbd> tag on its own, a request to <kbd>/blog</kbd> and <kbd>/blog?utm_source=F1GMAT</kbd> refer to the same page, but would result in addi­tion­al <kbd>craft_templatecaches</kbd> entries.

If you end up with a large num­ber of entries in the <kbd>craft_templatecaches</kbd> data­base table, it can actu­al­ly hin­der per­for­mance rather than help it — which defeats the whole point of caching to begin with! Pix­el & Ton­ic is actu­al­ly chang­ing the default behav­ior of the <kbd>`{% cache %}`</kbd> tag in Craft 3 to not include the query string, for this very reason.

If you are using the [Retour](https://github.com/nystudio107/retour) plu­g­in, and you are imple­ment­ing <kbd>`{% cache %}`</kbd> tags in your <kbd>_layout.twig</kbd> that oth­er tem­plates extend, you might con­sid­er using a pat­tern like this:

```

{% cache globally using key craft.request.path unless craft.retour.getHttpStatus != 200 %}

```

This will cause it to ignore the query string for the cache key, and also nev­er cache any­thing that’s not a  **200**  **OK** [http sta­tus code](https://httpstatuses.com/). This is need­ed for prop­er error han­dling as described in the [Han­dling Errors Grace­ful­ly in Craft CMS](https://nystudio107.com/blog/handling-errors-gracefully-in-craft-cms) article.

Keep in mind that if you use <kbd>`{% cache globally using key craft.request.path %}`</kbd> you can only have one <kbd>`{% cache %}`</kbd> tag per page, because the unique _key_ will be the <kbd>craft.request.path</kbd>. So if you require more than one <kbd>`{% cache %}`</kbd> tag on a page, add a descrip­tive name to the key to make it unique, such as <kbd>`{% cache globally using key "header-block" ~ craft.request.path %}`</kbd>.

Think about what is on your page, and how it might best be to cache it effectively.

## Craft 3.x Example

This is an exam­ple that cov­ers Craft 3.x specif­i­cal­ly; although most of the code is sim­i­lar for Craft 2.x, the way the default cache key is deter­mined is different.

```

{# -- Our blog entry -- #}
{% cache %}
    <article>
        <h1>{{ entry.title }}</h1>
        <p>{{ entry.body }}</p>
        <img src="{{ entry.image.first().getUrl(myTransform) }}">
    </article>
{% endcache %}

{# -- Our blog archives -- #}
{% cache globally using key "blog-archives" %}
    <section>
        {% for blogArchive in craft.entries.section('blog') %}
            <h1>{{ blogArchive.title }}</h1>
            <p>{{ blogArchive.summary }}</p>
        {% endfor %}
    </section>
{% endcache %}

```

Here we have two sep­a­rate caches on one page. The first is for our actu­al blog entry; the sec­ond is a _glob­al­ly_ cached out­put of our blog archives, stored in the data­base as <kbd>blog-archives</kbd>. This means that there is a unique cache of each blog entry, but a sin­gle _glob­al­ly_ shared cache of our blog archives.

Which is great, because we don’t want every sin­gle blog page to have to be re-cached when­ev­er we add a new blog entry. It’ll just re-cache the blog archives cache, which all of our blog pages share.

You’ll also notice that unlike the Craft 2.x exam­ple, we’re just using the <kbd>`{% cache %}`</kbd> tag on its own. Pix­el & Ton­ic changed the default behav­ior of the <kbd>`{% cache %}`</kbd> tag in Craft 3 to not include the query string, so it saves us from hav­ing to do it on our own.

If you are using the [Retour](http://github.com/nystudio107/craft-retour) plu­g­in for Craft 3, and you are imple­ment­ing <kbd>`{% cache %}`</kbd> tags in your <kbd>_layout.twig</kbd> that oth­er tem­plates extend, you might con­sid­er using a pat­tern like this:

```

{% cache unless craft.retour.getHttpStatus != 200 %}

```

This will cause it to nev­er cache any­thing that’s not a  **200**  **OK** [http sta­tus code](https://httpstatuses.com/). This is need­ed for prop­er error han­dling as described in the [Han­dling Errors Grace­ful­ly in Craft CMS](https://nystudio107.com/blog/handling-errors-gracefully-in-craft-cms) article.

Think about what is on your page, and how it might best be to cache it effectively.

## Cache Exemp­tions

A rea­son­ably com­mon pat­tern is that you want to cache your entire web­page, but there are cer­tain excep­tions that you don’t want cached. Let’s call them _cache exemp­tions_.

For instance, you might want to cache all of you pages by putting a <kbd>`{% cache %}`</kbd> tag in your main <kbd>layout.twig</kbd> file, as men­tioned above. But we don’t want to cache pages with non-<kbd>200</kbd> [http sta­tus codes](https://httpstatuses.com/), and maybe we don’t want to cache cer­tain pages like search results pages, and so on.

A nice pat­tern you can use is some­thing like this:

**CRAFT 2.x EXAMPLE:**

```

{# ##### Craft 2.x Cache exemption ##### #}
{% set cacheExempt = false %}
{# Exempt certain pages #}
{% set cacheExemptSegments = [
    'dont-cache-me-bro',
] %}
{% if craft.request.getSegment(1) in cacheExemptSegments %}
    {% set cacheExempt = true %}
{% endif %}
{# Also exempt pages with non-200 OK status codes #}
{% if craft.retour.getHttpStatus != 200 %}
    {% set cacheExempt = true %}
{% endif %}
{# Add any cache exemption conditions #}
...

{% cache globally using key craft.request.path unless cacheExempt %}

```

**CRAFT 3.x EXAMPLE:**

```

{# ##### Craft 3.x Cache exemption ##### #}
{% set cacheExempt = false %}
{# Exempt certain pages #}
{% set cacheExemptSegments = [
    'dont-cache-me-bro',
] %}
{% if craft.app.request.getSegment(1) in cacheExemptSegments %}
    {% set cacheExempt = true %}
{% endif %}
{# Also exempt pages with non-200 OK status codes #}
{% if craft.retour.getHttpStatus != 200 %}
    {% set cacheExempt = true %}
{% endif %}
{# Add any cache exemption conditions #}
...

{% cache unless cacheExempt %}

```

Using this tech­nique, you can add as many pages as you like to the <kbd>cacheExemptSegments</kbd> array, and any request that match­es the first seg­ment won’t be cached. You can leave this code in with an emp­ty array to have it not exempt any pages by first seg­ment, to future-proof things in case you need to down the road.

You can then add any oth­er con­di­tions you might have, which makes this pat­tern exten­si­ble, and it also keeps your actu­al <kbd>`{% cache %}`</kbd> tag fair­ly clean.

## A Peek Under the Hood

So let’s get down and dirty, and have a look at what the entries in the <kbd>craft_templatecaches</kbd> table actu­al­ly look like. Here’s the table schema for the <kbd>craft_templatecaches</kbd> table:

```

MariaDB [nystudio]> describe craft_templatecaches;
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| cacheKey | varchar(255) | NO | | NULL | |
| locale | char(12) | NO | MUL | NULL | |
| path | varchar(255) | YES | | NULL | |
| expiryDate | datetime | NO | | NULL | |
| body | mediumtext | NO | | NULL | |
+------------+--------------+------+-----+---------+----------------+
6 rows in set (0.00 sec)

```

The cache entries are sen­si­bly done on a per-<kbd>locale</kbd> basis, and have a <kbd>cacheKey</kbd> and a <kbd>path</kbd> that unique­ly iden­ti­fy them. If we just use the reg­u­lar old <kbd>`{% cache %}`</kbd> tag for our pages, the data­base entries in the table might look some­thing like this:

```

MariaDB [nystudio]> select cacheKey,path from craft_templatecaches;
+--------------------------------------+--------------------------------------------------+
| cacheKey | path |
+--------------------------------------+--------------------------------------------------+
| blog-archives | NULL |
| yYNGYDNbbsxeRCDCWhBqbmpHbN2NBELomimv | site:blog |
| yYNGYDNbbsxeRCDCWhBqbmpHbN2NBELomimv | site:blog/creating-optimized-images-in-craft-cms |
+--------------------------------------+--------------------------------------------------+

```

As you can see, Craft stores both a <kbd>cacheKey</kbd> and a <kbd>path</kbd> for each entry. These two in com­bi­na­tion are what describe a unique entry in the <kbd>craft_templatecaches</kbd> table. The <kbd>cacheKey</kbd> is what we asked it to be for our glob­al <kbd>blog-archives</kbd>, and is a ran­dom hash for places where we just used the reg­u­lar old <kbd>`{% cache %}`</kbd> tag.

If we instead use the <kbd>`{% cache globally using key craft.request.path %}`</kbd> pat­tern, our <kbd>craft_templatecaches</kbd> ends up look­ing like this:

```

MariaDB [nystudio]> select cacheKey,path from craft_templatecaches;
+---------------------------------------------+----------------+
| cacheKey | path |
+---------------------------------------------+----------------+
| blog-archives | NULL |
| blog | NULL |
| blog/creating-optimized-images-in-craft-cms | NULL |
+---------------------------------------------+----------------+

```

As you can see, it’s using the <kbd>craft.request.path</kbd> for the key, and there’s noth­ing stored in the <kbd>path</kbd>. If we don’t strip the query string out on Craft 2.x (this won’t be an issue on Craft 3.x) via <kbd>`{% cache globally using key craft.request.path %}`</kbd>, we could end up with a <kbd>craft_templatecaches</kbd> table that looks like this:

```

MariaDB [nystudio]> select cacheKey,path from craft_templatecaches;
+--------------------------------------+--------------------------------------------------+
| cacheKey | path |
+--------------------------------------+--------------------------------------------------+
| blog-archives | NULL |
| yYNGYDNbbsxeRCDCWhBqbmpHbN2NBELomimv | site:blog |
| yYNGYDNbbsxeRCDCWhBqbmpHbN2NBELomimv | site:blog?utm_source=F1GMAT |
| yYNGYDNbbsxeRCDCWhBqbmpHbN2NBELomimv | site:blog?utm_source=ADG12F |
| yYNGYDNbbsxeRCDCWhBqbmpHbN2NBELomimv | site:blog?utm_source=GS13FA |
| yYNGYDNbbsxeRCDCWhBqbmpHbN2NBELomimv | site:blog?utm_source=SM66MS |
| yYNGYDNbbsxeRCDCWhBqbmpHbN2NBELomimv | site:blog?utm_source=CMBKA4 |
| yYNGYDNbbsxeRCDCWhBqbmpHbN2NBELomimv | site:blog?utm_source=HGHAJ2 |
| yYNGYDNbbsxeRCDCWhBqbmpHbN2NBELomimv | site:blog?utm_source=24GSJ2 |
+--------------------------------------+--------------------------------------------------+

```

And on and on. We can end up with a ton of entries in the <kbd>craft_templatecaches</kbd> table that are real­ly the same thing, which can result in per­for­mance degra­da­tion, and the dread­ed hung _Delet­ing Stale Tem­plate Caches_ task.

The same is true for the case where we <kbd>`{% cache %}`</kbd> things in our <kbd>_layout.twig</kbd> file, and our 404 tem­plate extends that <kbd>_layout.twig</kbd>: if we don’t exclude 404 Not Found http sta­tus codes, we’ll end up with a <kbd>craft_templatecaches</kbd> entry for every sin­gle 404 that hits our site. Every. Sin­gle. One.

And believe me, there are swarms of bots out there on the Inter­net that probe your web­sites every day look­ing for vul­ner­a­bil­i­ties that will gen­er­ate a mas­sive num­ber of 404 errors, and can cause seri­ous per­for­mance impli­ca­tions for your website.

So cache wisely.

## But wait, there’s more!

We can go even fur­ther down the rab­bit hole. In addi­tion to the <kbd>templatecaches</kbd> table, Craft keeps track of some addi­tion­al infor­ma­tion for each cache entry.

![But Wait Theres More](https://nystudio107-ems2qegf7x6qiqq.netdna-ssl.com/img/blog/_1200x675_crop_center-center_82_line/but-wait-theres-more.jpg)

To help with the auto­mat­ic cache break­ing, Craft also has a table called <kbd>templatecacheelements</kbd> that keeps track of any Ele­ments (Entries, Catagories, Assets, etc.) that are inside of a giv­en <kbd>`{% cache %}`</kbd> tag:

```

MariaDB [craft3]> select * from templatecacheelements;
+---------+-----------+
| cacheId | elementId |
+---------+-----------+
| 1 | 4 |
| 2 | 85 |
| 2 | 80 |
| 2 | 81 |
| 2 | 73 |
| 2 | 74 |
| 2 | 4 |
| 2 | 83 |
+---------+-----------+
8 rows in set (0.00 sec)

```

Note that there is a row for each <kbd>templatecaches</kbd> id. This is so that if an ele­ment _inside_ of a <kbd>`{% cache %}`</kbd> tag is changed, Craft can automag­i­cal­ly break the cache. But note that it also means that if we have a whole lot of ele­ments inside of our <kbd>`{% cache %}`</kbd> tags, we can end up with a whole lot of rows in this table:

```

MariaDB [imawhale]> select * from craft_templatecacheelements;
+---------+-----------+
| cacheId | elementId |
+---------+-----------+
| 12160 | 2 |
| 12160 | 369 |
| 12160 | 370 |
| 12160 | 55 |
| 12160 | 57 |
| 12160 | 58 |
| 12160 | 56 |
| 12160 | 59 |
| 12160 | 297 |
| 12160 | 233 |
...
24647 rows in set (0.03 sec)

```

So if we have a web­site with 10,000 blog entries on it, and each blog has 10 ele­ments inside of the <kbd>`{% cache %}`</kbd> tag, that means we’ll end up with 10,000 rows in the <kbd>templatecaches</kbd> table, and 100,000 rows in the <kbd>templatecacheelements</kbd> table. For the blog alone.

Sim­i­lar­ly, there’s anoth­er table that Craft uses to keep track of Ele­ment Cri­te­ria (<kbd>templatecachecriteria</kbd>) for Craft 2.x, and Ele­ment Queries (<kbd>templatecachequeries</kbd>) for Craft 3.x.

**CRAFT 2.x ELE­MENT CRITERIA:**

```

MariaDB [imawhale]> select * from craft_templatecachecriteria;
+--------+---------+------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| id | cacheId | type | criteria |
+--------+---------+------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 113997 | 12160 | Entry | {"ancestorDist":null,"ancestorOf":null,"archived":0,"dateCreated":null,"dateUpdated":null,"descendantDist":null,"descendantOf":null,"fixedOrder":0,"id":null,"indexBy":null,"level":null,"limit":100,"locale":"en","localeEnabled":1,"nextSiblingOf":null,"offset":0,"order":"lft, postDate desc","positionedAfter":null,"positionedBefore":null,"prevSiblingOf":null,"relatedTo":null,"ref":null,"search":null,"siblingOf":null,"slug":"twitch-nav","status":"live","title":null,"uri":null,"with":null,"childField":null,"childOf":null,"depth":null,"parentField":null,"parentOf":null,"after":null,"authorGroup":null,"authorGroupId":null,"authorId":null,"before":null,"editable":0,"expiryDate":null,"postDate":null,"section":"navigation","sectionId":null,"type":null} |
| 113998 | 12160 | MatrixBlock | {"ancestorDist":null,"ancestorOf":null,"archived":0,"dateCreated":null,"dateUpdated":null,"descendantDist":null,"descendantOf":null,"fixedOrder":0,"id":null,"indexBy":null,"level":null,"limit":100,"locale":"en","localeEnabled":1,"nextSiblingOf":null,"offset":0,"order":"matrixblocks.sortOrder","positionedAfter":null,"positionedBefore":null,"prevSiblingOf":null,"relatedTo":null,"ref":null,"search":null,"siblingOf":null,"slug":null,"status":"enabled","title":null,"uri":null,"with":null,"childField":null,"childOf":null,"depth":null,"parentField":null,"parentOf":null,"fieldId":"28","ownerId":"369","ownerLocale":null,"type":null} |
...
22745 rows in set (0.04 sec)

```

**CRAFT 3.x ELE­MENT QUERIES:**

```

MariaDB [craft3]> select * from templatecachequeries;
+----+---------+----------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| id | cacheId | type | query |
+----+---------+----------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 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tZVJpY2hUZXh0IjtOO3M6ODoic29tZVVuaXQiO047czo1OiJzdHVmZiI7TjtzOjEwOiJ0ZXN0SU1hZ2VzIjtOO3M6NDoid29vZiI7TjtzOjUxOiIAY3JhZnRcYmVoYXZpb3JzXENvbnRlbnRCZWhhdmlvcgBfY3VzdG9tRmllbGRWYWx1ZXMiO2E6MDp7fXM6NToib3duZXIiO3I6MTt9fXM6NToid2hlcmUiO047czo1OiJsaW1pdCI7aToxO3M6Njoib2Zmc2V0IjtpOjA7czo3OiJpbmRleEJ5IjtOO3M6MTY6ImVtdWxhdGVFeGVjdXRpb24iO2I6MDt9 |
+----+---------+----------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
4 rows in set (0.00 sec)

```

Although the nomen­cla­ture is dif­fer­ent, the pur­pose is the same: to keep track of where you might have queries like <kbd>`{% craft.entries.section('blog').limit(20) %}`</kbd> in your templates.

This is so that if an ele­ment changes _inside_ one of your queries that’s in a <kbd>`{% cache %}`</kbd> tag, the cache will be bust­ed to reflect the new data.

If you’re won­der­ing why the Craft 3.x query looks the way it does, it is because this is a seri­al­ized ver­sion of the bina­ry Query object.

Again, note that if you have a whole lot of queries inside of your <kbd>`{% cache %}`</kbd> tags, you’re going to end up with a whole lot of rows in the database.

If we have a web­site with 10,000 blog entries on it, and each blog has 10 Ele­ment Queries inside of the <kbd>`{% cache %}`</kbd> tag, that means we’ll end up with 10,000 rows in the <kbd>templatecaches</kbd> table, and 100,000 rows in the <kbd>templatecachequeries</kbd> or <kbd>templatecachecriteria</kbd> tables. For the blog alone.

## Cache as Cache Can

The <kbd>`{% cache %}`</kbd> tag can do a whole lot more, which you can read up on at the [Craft Tem­plat­ing Docs](https://craftcms.com/docs/templating/cache) page. Hope­ful­ly this gen­tle intro­duc­tion got you think­ing about when and how to use it.

If you want the ulti­mate in cache-based per­for­mance, check out the [Sta­t­ic Page Caching with Craft CMS](https://nystudio107.com/blog/static-caching-with-craft-cms) article.

## Further Reading

_If you want to be notified about new articles, follow [nystudio107](https://twitter.com/nystudio107) on Twitter._

<small>Copyright ©2020 nystudio107. Designed by nystudio107</small>