<p>Left to itself, the <code>{% cache %}</code> tag will cache the content per-url. The problem you have is that the same url sometimes has $'s, and sometimes has GBP.</p>

<p>You can use the <a href="https://craftcms.com/docs/templating/cache#using-key" rel="nofollow">using key</a> feature to cache based on the url <em>and</em> the currency:</p>

<pre><code>{% cache globally using key craft.request.path ~ craft.geo.info.currency_symbol %}
</code></pre>

<p>(<code>craft.geo.info.currency_symbol</code> may not be the best disambiguator string, but this should get you started.)</p>

CC BY-SA 3.0
2016-09-04T18:41:09.817Z
My currency symbol is not in the url - are you suggesting nesting a global cache call for each url within the entry loop cache? I think i am missing something in how this might solve the issue.
joomkit
CC BY-SA 3.0
2016-09-04T22:26:28.530Z
You cache on a key that contains both the url and the currency symbol. So when two people hit the same url and are using the same currency symbol, they get the same cache entry, but when two people hit the same url using different currency symbols, they get different cache entries. `~` is the string concatination operator.
Marion Newlevant
CC BY-SA 3.0
2016-09-02T16:24:14.053Z
2016-09-02T16:24:14.053Z
Marion Newlevant
<p>In my base template i set some variables  like currency , currency symbol based on the IP address detected. This is done from a geolocation plugin which caches the result (ip,currency, currency symbol,lang) and makes them available to the template as {{craft.geo.info.currency}}</p>

<p>The problem:</p>

<p>Our site is in UK
When a visitor from overseas eg. USA comes they get dollar prices and conversions etc</p>

<p>However, in the product list template I am caching the entry loop with cache tags and rendering the currency symbol with the plugins global template variable like this:</p>

<pre><code>{{ craft.geo.info.currency_symbol |raw}} price XX
</code></pre>

<p>USA ip addresses sees US dollars - great!</p>

<p>However in the UK view of product list, and within the product page template loop, we suddenly see the dollar symbol too.</p>

<p>In my footer i spit out the <code>{{craft.geo.info.currency_symbol}}</code> with no cache tags and I get UK GBP currency as I expect.</p>

<p>I guess Craft/Twig is just showing the template cache regardless of plugin variable?</p>

<p>Is there a way around this?</p>

<p>My solution for now is to remove the cache tags from the product list - its not that many products and performance is still good - but I'd like to know how to combine the plugin currency symbol variable within the cached loop.</p>

<cache>
How can I bust a template cached plugin variable in a loop?
# How can I bust a template cached plugin variable in a loop?

(Asked by: username_0 on 2016-09-02)

In my base template i set some variables  like currency , currency symbol based on the IP address detected. This is done from a geolocation plugin which caches the result (ip,currency, currency symbol,lang) and makes them available to the template as {{craft.geo.info.currency}}
The problem:
Our site is in UK
When a visitor from overseas eg. USA comes they get dollar prices and conversions etc
However, in the product list template I am caching the entry loop with cache tags and rendering the currency symbol with the plugins global template variable like this:
{{ craft.geo.info.currency_symbol |raw}} price XX

USA ip addresses sees US dollars - great!
However in the UK view of product list, and within the product page template loop, we suddenly see the dollar symbol too.
In my footer i spit out the {{craft.geo.info.currency_symbol}} with no cache tags and I get UK GBP currency as I expect.
I guess Craft/Twig is just showing the template cache regardless of plugin variable?
Is there a way around this?
My solution for now is to remove the cache tags from the product list - its not that many products and performance is still good - but I'd like to know how to combine the plugin currency symbol variable within the cached loop.

**Tags:** cache

---

## 1 answers

### Answer by username_1 on 2016-09-02. Score: 1 | Accepted answer

Left to itself, the {% cache %} tag will cache the content per-url. The problem you have is that the same url sometimes has $'s, and sometimes has GBP.
You can use the using key feature to cache based on the url and the currency:
{% cache globally using key craft.request.path ~ craft.geo.info.currency_symbol %}

(craft.geo.info.currency_symbol may not be the best disambiguator string, but this should get you started.)

> **Comments:**
> **username_0**: My currency symbol is not in the url - are you suggesting nesting a global cache call for each url within the entry loop cache? I think i am missing something in how this might solve the issue.  
> **username_1**: You cache on a key that contains both the url and the currency symbol. So when two people hit the same url and are using the same currency symbol, they get the same cache entry, but when two people hit the same url using different currency symbols, they get different cache entries. `~` is the string concatination operator.  

---

