<p>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 <code>{% cache %}</code> tag. When we cleared the template cache, the site would be fast again until the cache grew in size and got slow again.</p>

<p>It was our uninformed use of the <code>{% cache %}</code> tag that contributed to this. </p>

<p>It's important to firstly understand that <strong>using <code>{% cache %}</code> without any parameters generates a separate copy of the block for every single URL that uses it</strong>. If the page is requested with a different querystring, again the block is regenerated and a new copy is saved to the cache. This means you could potentially have many dozens, hundreds, or even thousands of copies of the same block in your cache.</p>

<p>Because we had several search pages with URLs like <code>/search?q=searchterm</code>, this kept creating more and more cached blocks every time somebody did a search.</p>

<p>So in our case we had to be more explicit when using the cache tag, in two ways:</p>

<ol>
<li><p>For any block that should always output the same, regardless of URL, use  </p>

<pre><code>{% cache globally %}
</code></pre></li>
<li><p>For any block that <em>does</em> change based on URL, but perhaps not on querystring (such as perhaps a menu/nav block) then use something like:  </p>

<pre><code>{% cache globally using key "navbar:" ~ craft.request.path %}
</code></pre>

<p>(as mentioned in the <a href="https://craftcms.com/docs/templating/cache" rel="nofollow noreferrer">Craft docs</a>)</p></li>
</ol>

<p>And here are the results:</p>

<p><a href="https://i.sstatic.net/8eH6H.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/8eH6H.png" alt="Craft CMS cache slowness"></a></p>

CC BY-SA 3.0
2017-10-30T22:30:06.770Z
2017-10-30T23:32:49.030Z
2017-10-30T23:32:49.030Z
Simon East
<p>This will probably help you: <a href="https://nystudio107.com/blog/the-craft-cache-tag-in-depth" rel="nofollow noreferrer">The Craft {% cache %} Tag In-Depth</a></p>

CC BY-SA 3.0
2017-10-31T06:16:05.527Z
2017-10-31T06:16:05.527Z
andrew.welch
<p>This article (<a href="http://buildwithcraft.com/help/stuck-tasks" rel="nofollow">http://buildwithcraft.com/help/stuck-tasks</a>) from Brad's comment was indeed the way to address this - and our logs did show this exceeding the php execution time. Thanks Brad!</p>

CC BY-SA 3.0
2015-04-17T00:07:21.830Z
2015-04-17T00:07:21.830Z
Mike
<p>We have a site that is performing very poorly with very long load times and I'm guessing it may be related to caching but have no idea how/why.</p>

<p>The site's homepage was loading very slowly while in development due to a mega menu with a lot of queries to create primary and secondary navigation. I cached that globally while in dev and the page performance improved about 70%. I did some further global caching {% cache globally %} for things like the site footer and than added some regular caching {% cache %} for entry-specific template content.</p>

<p>Once this was all done, performance was very good. However, then we launched the site and took the site out of dev mode (which is had previously been in). The launch was on the same account - nothing changed - just pointed the DNS to this account.</p>

<p>Since that time, performance has been poor again. Further, when logging into the control panel, we always see this (which we never saw while in dev mode):</p>

<p><img src="https://i.sstatic.net/hZX3Q.png" alt="image of cp stale template progress"></p>

<p>What's odd also is the circle and bar progress indicators are always in the exactly pictured state - they're never more or less along in terms of position (over the course of weeks).</p>

<p>Lastly, if I go into the CP settings area and Clear Caches, performance seems to pick up again for a little while.</p>

<p>I'm at a complete loss as to what may be happening that is causing these issue and any help would be greatly appreciated.</p>

<p>Thanks,
Mike</p>

CC BY-SA 3.0
2015-04-16T22:08:59.450Z
Your progress indicator suggests that you've got a stuck task. Use this to help debug why: http://buildwithcraft.com/help/stuck-tasks
Brad Bell
CC BY-SA 3.0
2015-04-16T22:31:01.763Z
Ok - thanks. I'll check that and see what I find.
Mike
<cache><devmode>
Cache issues making site super slow in production but not in dev mode
# Cache issues making site super slow in production but not in dev mode

(Asked by: username_0 on 2015-04-16)

We have a site that is performing very poorly with very long load times and I'm guessing it may be related to caching but have no idea how/why.

The site's homepage was loading very slowly while in development due to a mega menu with a lot of queries to create primary and secondary navigation. I cached that globally while in dev and the page performance improved about 70%. I did some further global caching {% cache globally %} for things like the site footer and than added some regular caching {% cache %} for entry-specific template content.

Once this was all done, performance was very good. However, then we launched the site and took the site out of dev mode (which is had previously been in). The launch was on the same account - nothing changed - just pointed the DNS to this account.

Since that time, performance has been poor again. Further, when logging into the control panel, we always see this (which we never saw while in dev mode):

![image of cp stale template progress](https://i.sstatic.net/hZX3Q.png)

What's odd also is the circle and bar progress indicators are always in the exactly pictured state - they're never more or less along in terms of position (over the course of weeks).

Lastly, if I go into the CP settings area and Clear Caches, performance seems to pick up again for a little while.

I'm at a complete loss as to what may be happening that is causing these issue and any help would be greatly appreciated.

Thanks,
username_0

**Tags:** cache, devmode

> **Comments:**
> **username_1**: Your progress indicator suggests that you've got a stuck task. Use this to help debug why: http://buildwithcraft.com/help/stuck-tasks  
> **username_0**: Ok - thanks. I'll check that and see what I find.  

---

## 3 answers

### Answer by username_0 on 2015-04-17. Score: 4 | Accepted answer

This article (<http://buildwithcraft.com/help/stuck-tasks>) from Brad's comment was indeed the way to address this - and our logs did show this exceeding the php execution time. Thanks Brad!


---

### Answer by username_2 on 2017-10-30. Score: 4

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 we cleared the template cache, the site would be fast again until the cache grew in size and got slow again.
It was our uninformed use of the {% cache %} tag that contributed to this. 
It's important to firstly understand that using {% cache %} without any parameters generates a separate copy of the block for every single URL that uses it. If the page is requested with a different querystring, again the block is regenerated and a new copy is saved to the cache. This means you could potentially have many dozens, hundreds, or even thousands of copies of the same block in your cache.
Because we had several search pages with URLs like /search?q=searchterm, this kept creating more and more cached blocks every time somebody did a search.
So in our case we had to be more explicit when using the cache tag, in two ways:

For any block that should always output the same, regardless of URL, use  
{% cache globally %}

For any block that does change based on URL, but perhaps not on querystring (such as perhaps a menu/nav block) then use something like:  
{% cache globally using key "navbar:" ~ craft.request.path %}

(as mentioned in the Craft docs)

And here are the results:


---

### Answer by username_3 on 2017-10-31. Score: 1

This will probably help you: [The Craft {% cache %} Tag In-Depth](https://nystudio107.com/blog/the-craft-cache-tag-in-depth)


---

