Multi-currency Websites

cache
#1

Hi,

I’ve got an e-website which serves a global user-base in multiple currencies. The documentation for CloudFlare seems to suggest that the CDN cache is based only on the URL, this works where different markets have separate domains — but some markets use the same domain serving content in multiple currencies. Can the cache be configured to account for an additional header or cookie which specifies the currency as a shard?

1 Like
#2

You could probably add ?currency=aa since query strings are part of the cache key.

Also note that you should only worry about the CF cache if you dynamically tell the user what currency they use via js or css files (files served from cache) or if you use a ‘cache everything’ page rule. If you tell the client what currency to use based off of its IP address, or via the actual HTML page, CF shouldn’t be caching the currency anyways.

#3

Thanks,

I want CF to cache the page HTML as some pages are large and take a long time to transfer to some users (particularly in Australia). The currency is defaulted but can be changed by the user and is persisted via a cookie. Unfortunately I’m unable to add the currency to the URL so would need to include a header or cookie as part of the cache key.

#4

The only way to manipulate the cache with a cookie is “bypass cache on cookie” but that just disables the cache if that cookie is present. Unfortunately I don’t think this is possible.

#5

On Cloudflare’s Enterprise Plan you can create a custom cache key based on cookie in page rules or Workers.

#6

Couldn’t you do this with a worker, read the cookie and add the currency to the request on the fly?

#7

I am afraid I dont get the connection between currency and cache. Just because some goes e.g. via a US datacentre does not necessarily mean that person will use USD as currency.

Unless there is something I am missing I would say the approach is wrong in this case. If you really want to outsource the currency selection to Cloudflare I’d say the worker approach mentioned by @thedaveCA might be the most feasible option.

closed #8

This topic was automatically closed after 30 days. New replies are no longer allowed.