Clearing caches when exchange rates change
Cached pages keep the prices that were worked out when the page was cached. If the euro rises 2% against your store currency overnight, a page cached yesterday still shows yesterday’s EUR prices. WC Currency Switch can clear your page caches by itself when exchange rates move by more than an amount you choose, so shoppers see up-to-date prices without you clearing caches by hand. Small daily moves are ignored, so your cache is not emptied every few hours for nothing.
How it works#
Every time new exchange rates are saved, either when the rate cache runs out (see Rate Cache TTL on the Rate Provider tab) or when you click Force Refresh, the plugin compares the new rates with the ones in use until then.
For each enabled currency, it works out how much the currency moved against your store currency. If the largest move is more than your threshold, the plugin clears these caches, if they are active on your site:
- xSpeed Cache
- LiteSpeed Cache
- WP Rocket
- W3 Total Cache
- WP Super Cache
- your Bunny CDN pull zone, through Nahnu Cache Connector for Bunny.net or, if that is not connected, through Super Page Cache’s Bunny connector
The clearing runs at the end of the request that saved the new rates, after that page has been sent, so it does not slow down a visitor.
Set it up#
- Go to WooCommerce > Currency Switch > Rate Provider.
- Find Clear page cache when a rate moves more than.
- Enter a percentage. The default is 1. You can enter 0 to 50, in steps of 0.1.
- Click Save Changes.
Enter 0 to turn automatic clearing off.
Below the field, the plugin shows when caches were last cleared and which ones, for example “Last cleared 3 hours ago: LiteSpeed, Bunny CDN”. If no supported cache was found, it says “no supported cache found”.
Examples#
A move above the threshold. Your store sells in USD, with EUR and KWD enabled. The threshold is 1%. Yesterday 1 USD = 0.9200 EUR. Today’s refresh says 1 USD = 0.9338 EUR.
- Move: 0.9338 / 0.9200 = 1.015, so EUR moved 1.5%.
- 1.5% is more than 1%, so the caches are cleared.
A move below the threshold. Today’s refresh says 1 USD = 0.9250 EUR instead.
- Move: 0.9250 / 0.9200 = 1.0054, so EUR moved 0.54%.
- KWD moved even less.
- The largest move is below 1%, so nothing is cleared. Cached pages keep the old EUR prices until they are cleared for another reason.
A fixed rate. You set a fixed exchange rate for KWD on the Pricing tab. KWD prices do not follow the market, so KWD is left out of the check, however much its market rate moves.
Good to know#
- The very first time rates are fetched there is nothing to compare with, so nothing is cleared.
- Only enabled currencies count. Your store currency is never checked, because it does not move against itself.
- Pages are not rebuilt straight away. Your cache plugin rebuilds each page the next time someone visits it.
- A lower threshold keeps prices closer to the market but clears your caches more often. A higher threshold keeps more pages cached but lets prices drift further.
- Super Page Cache’s own disk cache and Cloudflare are not on the list above. If you use them, clear them yourself after a large rate move, or ask a developer to hook into the
wccs_page_cache_purgedaction, which runs after the plugin has cleared the caches it knows.
The cache is cleared when new rates are saved. With a Rate Cache TTL of 6 hours (the default), a large move is picked up within about 6 hours. Click Force Refresh to fetch new rates now.
Related docs#
- How WC Currency Switch works with page caching
- Cache plugin setup
- Choosing an exchange rate provider
- Fixed exchange rates