<p>So the caching issue I was having was on our blog overview page - a page on which you can do filtering to show entries of a certain category. Whenever someone would do a filter - the header would remain cached, when it should have updated to reflect the filter.</p>

<p>Anyway, I think in most cases @lazy pirate's solution would have worked but it wasn't working for me - possibly because the filtering was making it so Craft wasn't viewing the page as one single entry when a filter was run?</p>

<p>The solution I came to that worked for me was this:</p>

<pre><code>{% cache globally using key 'entry_' ~ entry.id ~ '_elements' unless entry is not defined or craft.request.segment(1) == 'blog' %}
</code></pre>

<p>That worked because 'blog' is always in the same position in the URL, even when filtered. Hope that helps someone! </p>

CC BY-SA 3.0
2017-05-19T18:08:42.630Z
2017-05-19T18:08:42.630Z
dpayne
<p>You could add a variable like <code>globalCacheDisabled</code> and <code>{% cache globally using key 'entry_' ~ entry.id ~ '_elements' unless globalCacheDisabled %}</code> and use a <code>{% set globalCacheDisabled = entry.disableGlobalCache %}</code> on the given page template.</p>

<p>On Craft's side I'd use a Lightswitch field on the entry with handle <code>disableGlobalCache</code>, which is disabled by default which you can then activate on the given entry/ies. </p>

<p>This makes you prone to changing id's and differences across environments. (While testing make sure to purge the cache)</p>

CC BY-SA 3.0
2017-05-04T09:45:39.853Z
2017-05-04T09:45:39.853Z
Max Strebel
<p>I have a template element that is used on almost every page of the site. I would like to cache that element globally, except on one particular page I would like it to just be a normal cache based on the page URL.</p>

<p>The current code I'm using is below, which is not working as intended. The global cache is still working on entry id 126.</p>

<pre><code>{% cache globally using key 'entry_' ~ entry.id ~ '_elements' unless entry is not defined or entry.id == '126' %}
</code></pre>

<p>What would be the best way to make that functionality work without slowing down any other pages? Thanks!</p>

CC BY-SA 3.0
2017-05-03T19:17:28.717Z
Just as a test try this on the entry 126 page: `{% cache globally using key 'entry_' ~ entry.id ~ '_elements' unless entry.id == '126' %}`
Brad Bell
CC BY-SA 3.0
2017-05-03T20:26:50.153Z
Hey @BradBell, thanks for the response. Tried the test and still seeing the same caching issues.
dpayne
CC BY-SA 3.0
2017-05-04T18:22:08.737Z
Are you sure it's entry 126?
RitterKnight
CC BY-SA 3.0
2017-05-04T20:20:32.040Z
@RitterKnight Yes. I also tried using entry.title and had the same problem. Still need to try the solution below and will update as appropriate but looks like that should work.
dpayne
<cache>
How to Cache Globally Except for One Page
# How to Cache Globally Except for One Page

(Asked by: username_0 on 2017-05-03)

I have a template element that is used on almost every page of the site. I would like to cache that element globally, except on one particular page I would like it to just be a normal cache based on the page URL.
The current code I'm using is below, which is not working as intended. The global cache is still working on entry id 126.
{% cache globally using key 'entry_' ~ entry.id ~ '_elements' unless entry is not defined or entry.id == '126' %}

What would be the best way to make that functionality work without slowing down any other pages? Thanks!

**Tags:** cache

> **Comments:**
> **username_1**: Just as a test try this on the entry 126 page: `{% cache globally using key 'entry_' ~ entry.id ~ '_elements' unless entry.id == '126' %}`  
> **username_0**: Hey @BradBell, thanks for the response. Tried the test and still seeing the same caching issues.  
> **username_2**: Are you sure it's entry 126?  
> **username_0**: @username_2 Yes. I also tried using entry.title and had the same problem. Still need to try the solution below and will update as appropriate but looks like that should work.  

---

## 2 answers

### Answer by username_0 on 2017-05-19. Score: 2 | Accepted answer

So the caching issue I was having was on our blog overview page - a page on which you can do filtering to show entries of a certain category. Whenever someone would do a filter - the header would remain cached, when it should have updated to reflect the filter.
Anyway, I think in most cases @lazy pirate's solution would have worked but it wasn't working for me - possibly because the filtering was making it so Craft wasn't viewing the page as one single entry when a filter was run?
The solution I came to that worked for me was this:
{% cache globally using key 'entry_' ~ entry.id ~ '_elements' unless entry is not defined or craft.request.segment(1) == 'blog' %}

That worked because 'blog' is always in the same position in the URL, even when filtered. Hope that helps someone!


---

### Answer by username_3 on 2017-05-04. Score: 3

You could add a variable like `globalCacheDisabled` and `{% cache globally using key 'entry_' ~ entry.id ~ '_elements' unless globalCacheDisabled %}` and use a `{% set globalCacheDisabled = entry.disableGlobalCache %}` on the given page template.

On Craft's side I'd use a Lightswitch field on the entry with handle `disableGlobalCache`, which is disabled by default which you can then activate on the given entry/ies.

This makes you prone to changing id's and differences across environments. (While testing make sure to purge the cache)


---

