Implementing dynamic caching depends on which caching system you use. Some caching systems can handle dynamic caching, and can serve different content depending on the selected currency (and other parameters), while others are too rigid and must be disabled on catalogue pages.In this article you can find our recommended approach for the most common caching systems. 


Important
  • The solutions offered are provided as a reference, and may have to be adapted to your specific site. We cannot offer free support in relation to them. If you need assistance implementing them, you can avail of our paid support services. 
  • If you use our Currency Switcher for WooCommerce, make sure that the plugin's geolocation feature is enabled in WooCommerce > Currency Switcher Options > Geolocation (see below).

    This is required for the solutions below to work correctly.
    Please note that this geolocation option is independent from the one provided by WooCommerce 2.4 and later. We normally recommend to keep WooCommerce geolocation feature disabled, to improve performance, as dynamic caching doesn't need it.

Caching Plugins

ZenCache/Comet Cache (both free and paid version)
ZenCache/CometCache supports dynamic caching out of the box, both in the free and paid versions. To use such feature, please follow the instructions below:
  1. On your site, create folder /wp-content/ac-plugins.
  2. Download the Aelia Advanced Caching Plugin for Comet Cache/ZenCache (file aelia-zencache-ac-plugin.zip).
  3. Extract the caching module in the folder you created at step #1.
ZenCache/Comet Cache will load the Advanced Caching Module automatically, serving the correct content depending on the active currency, customer's country, and so on. No configuration is required.

Note

This caching plugin is more complex to configure than Comet Cache or other plugins, and requires the manual modification of configuration file. Before making any changes, we recommend to read in detail what needs to be done. If your technical skills are somewhat limited, switching to a simpler solution, like Comet Cache, is, in our opinion, a viable option.


To add dynamic caching to Super Cache, please follow the instructions below:

  1. Create a folder for the Super Cache plugins in /wp-content. For example, /wp-content/wpsc-plugins.
  2. Download the Aelia Advanced Caching Plugin for WP Super Cache (file aelia-wpsupercache-ac-plugin.zip).
  3. Extract the caching module in the folder you created at step #1.
  4. In wp-config.php, add the following line:
    $wp_cache_plugins_dir = '<full path to the folder you just created>';

    Example
    $wp_cache_plugins_dir = '/var/www/yoursite/wp-content/wpsc-plugins';

    This will make Super Cache look for its plugins in the folder you just created, instead of the default folder /wp-super-cache/plugins/. This change is needed because, when you update Super Cache, the whole WPSC plugin folder is deleted and recreated. By keeping the module outside of the plugin folder, it will be preserved when you update Super Cache.
  5. Configure Super Cache to set the caching mode to PHP or Legacy and enable dynamic caching (see below).

    Fig. 1 - Configure Super Cache in PHP or Legacy mode

    Fig. 2 - Enable Dynamic Caching

  6. Depending on your specific setup, you might also need to enable the "Late init" option in Super Cache settings (see below).
    Fig 3. - Enable Late Init


    Alternatively, you can add the following line to your wp-config.php file:

    $wp_super_cache_late_init = 1;

    If your page source contains a note saying "Super Cache dynamic page detected but late init not set. See the readme.txt for further details.", changing this setting should fix it (see Super Cache FAQ for technical details). Please note that this is not a requirement introduced by our plugin, it's how Super Cache handles dynamic caching.


That should be all. Your page will now be cached dynamically, taking into account information such as customer's currency, country and so on.

Should you encounter any difficulty configuring dynamic caching with WP Super Cache, we recommend that you open a support request on the plugin Support page (its developers know it in more details and will be able to help you troubleshooting any issue you might have with it).


WP Rocket

WP Rocket supports dynamic caching from version 2.7, available since the 11th March 2016. There is no configuration required to enable dynamic caching in such version. Simply install it, and dynamic caching will be enabled out of the box. Starting with version 2.8.15, WP Rocket also supports our Prices by Country or Tax Display by Country plugins. If you use an older version of WP Rocket, you will have to disable caching on catalogue pages to ensure that the correct content is displayed to visitors, or use an alternative solution.


Important

Installing WP Rocket on a site hosted by WP Engine won't introduce dynamic caching. This is because, in such configuration, the caching is still handled by the WP Engine systems, which don't support dynamic caching, while WP Rocket takes care of elements such as images, scripts and styles. If your site is hosted by WP Engine, we recommend to refer to the related section, below. The proposed solutions are still applicable, even after installing WP Rocket.


W3 Total Cache

W3 Total Cache does not support dynamic caching (which is different from the fragment caching feature that the plugin includes), due to restrictions in its architecture. The dynamic caching feature has been requested some time ago, therefore it's possible that will be introduced in the future. In the meantime, if you use such plugin, you can either switch to another solution (recommended), or install the free WooCommerce Cache Handler plugin.


WP Fastest Cache

WP Fastest Cache does not support dynamic caching, due to restrictions in its architecture. You can either switch to another solution, which supports dynamic caching (recommended), or install the free WooCommerce Cache Handler plugin as a workaround.


Caching Servers


Nginx

Nginx can handle dynamic caching with the appropriate configuration. Below you can find an example of how you can configure Nginx for that purpose.


IMPORTANT

  • This is an example configuration file, and the settings apply to the entire server. You should probably adapt these settings to apply to a specific location, instead, so that they only affect your specific ecommerce site. 
  • If you enter an incorrect configuration in Nginx, your web server could crash. If you are not familiar with Nginx configuration, we recommend to contact your developer, or hosting provider, who should be able to adjust the settings for you. We cannot provide assistance with the configuration of Nginx.   
    # Add Aelia cookies to the cache key. This will create multiple copies of each
    # cached page (one for each combination of currency, country and province/state)
    proxy_cache_key "$scheme$request_method$host$request_uri $cookie_aelia_cs_selected_currency$cookie_aelia_customer_country$cookie_aelia_customer_state$cookie_aelia_billing_country";
    
    # IMPORTANT
    # This is an example configuration file, and the settings apply to the entire server.
    # You should probably adapt these settings to apply to a specific location, instead,
    # so that they only affect your specific ecommerce site.
    #
    # If you are not familiar with Nginx configuration, we recommend to contact your
    # developer, or hosting provider, who should be able to adjust the settings for you.
    server {
      listen 80;
      server_name www.example.org;
    
      set $no_cache 0;
      # If none of the Aelia cookies are set, disable caching. This will ensure that
      # the page is loaded dynamically, and that cookies are set at the next load
      if ($cookie_aelia_cs_selected_currency$cookie_aelia_customer_country$cookie_aelia_customer_state$cookie_aelia_tax_exempt ~* "") {
        set $no_cache 1;
      }
        
      # Don't pull from cache based on $no_cache
      fastcgi_cache_bypass $no_cache;
      # Don't save to cache based on $no_cache
      fastcgi_no_cache $no_cache; 
    }

     

 

Varnish

Varnish automatically ignores the cache when the currency cookies are set, and should not require a specific configuration. Note: if your server uses Varnish, and removes the currency selection cookie, this may cause your server to send the same content to all your visitors. In such case, you should contact your System Administrator to amend the configuration, so that those cookies are taken into account when serving cached content.


You can refer to the following article to learn how to configure Varnish for dynamic caching: Cache WooCommerce Currency from GeoIP with Varnish 4 vmod.

If you are using Varnish and CloudFlare together, please refer to the following article to learn how to leverage the geolocation capabilities offered by CloudFlare within Varnish: Cache WooCommerce Currency from CloudFlare GeoIP with Varnish 4.


If you can't amend Varnish settings to implement dynamic caching, then you should either disable Varnish, or use the free WooCommerce Cache Handler plugin to work around such limitation. Caching of resources, such as JavaScript, CSS and images, can be left enabled.


CloudFlare

CloudFlare supports dynamic caching, but only on Enterprise plans. With any other plan, it's either necessary to disable caching on catalogue pages, or install the free WooCommerce Cache Handler plugin. In this second case, you must ensure that the caching level is set to standard in CloudFlare settings.

Caching of resources, such as JavaScript, CSS and images, can be left enabled, as it doesn't have an impact on the content of the page.


Sucuri CloudProxy

Sucuri CloudProxy doesn't yet supports dynamic caching. As with CloudFlare, you will have to disable it on catalogue pages, or install the free WooCommerce Cache Handler plugin. Caching of resources, such as JavaScript, CSS and images, can be left enabled.


Incapsula

The caching service provided by Incapsula doesn't yet supports dynamic caching. As with CloudFlare, you will have to disable it on catalogue pages, or install the free WooCommerce Cache Handler plugin. Caching of resources, such as JavaScript, CSS and images, can be left enabled. 


WP Engine

WP Engine does not yet support dynamic caching. We provided them with detailed information on how they could implement it, and they acknowledged that it could be a useful feature. However, they could not confirm if they would be able to implement it, nor when. Until they add such feature, you can disable caching on catalogue pages, or install the free WooCommerce Cache Handler plugin.


SiteGround

SiteGround offers several levels of caching. Their static caching will work fine, as it caches static resources, such as CSS and JavaScript. Their dynamic caching, despite its name,  is not really dynamic, it's static caching of dynamic content. It's possible, however, to use the SiteGround static caching feature together with one of the plugins listed above, to get optimal performance.


If you wish to enable the SiteGround's dynamic caching, you will have to install the free WooCommerce Cache Handler plugin to ensure that the correct content is served to your visitors.


GoDaddy

GoDaddy's caching does not yet support dynamic caching. Until they add such feature, you can disable caching on catalogue pages, or install the free WooCommerce Cache Handler plugin.


How to configure the Cache Handler plugin


The Cache Handler plugin can work around the limitations of rigid caching systems. Its purpose is to ensure that the correct content is served to the visitors, depending on their country, province, currency and tax status. Configuring the plugin is simple:


1. Download the Cache Handler plugin from our site.

2. Upload and activate the plugin. 

3. Go to WooCommerce > Settings > Cache Handler to configure the plugin. 

xLaPrZ397NXMuw5F1TYjIE2wlnDrcnur5g.png

 You will be presented with three options:
  • Disabled
    The Cache Handler will be disabled and won't do anything.
  • Enable Redirect
    The Cache Handler will use the same redirect mechanism adopted by WooCommerce to redirect users to the correct content. Visitor's will be redirected to pages that have a unique page identifier appended to the URL (e.g. http://example.org?ph=23985623985). The identifier will be unique for the combination of country, province, currency and tax status, and it will ensure that visitors will see the correct content.
  • Enable Ajax Loader
    The Cache Handler will use Ajax to load prices dynamically on each page. This method will trigger an Ajax request that will update "on the fly" all the prices found on a page. Its main drawback is that it cannot handle prices introduced by other plugins (e.g. pricing tables, product addons, etc). If you use that type of plugins, you should use the Enable Redirect method instead.

4. Choose the option that works best for your site, and save the settings.

5. Clear all the caching systems you are using (plugins, Nginx, Varnish, CloudFlare, etc). This is important, as it will allow the Cache Handler to add its scripts to your pages, and ensure that the correct content is served.


Technical details


If you would like to implement your own custom dynamic caching logic, you will have to keep track of the values of the following cookies:

  • aelia_cs_selected_currency - The active currency.
  • aelia_customer_country - Visitor's country.
  • aelia_customer_state - Visitor's State/Province/County.
  • aelia_billing_country - Visitor's country. Legacy cookie. It's no longer used by newer versions of Aelia plugins, but it's maintained for backward compatibility.
  • aelia_tax_exempt - Flag indicating if the customer is exempt from tax.
You should use the above information to generate a separate cache key for each combination of values, so that the same URL can show different content. That is, while the cache key is usually just the page URL, thus serving one content for one URL, the new cache key will have to be "URL + aelia_cs_selected_currency + aelia_customer_country + aelia_customer_state + aelia_billing_country + aelia_tax_exempt".

For the cookies to be set properly, the flow should be the following:
  1. First visit. Visitor doesn't have any of the above cookies set. Skip caching entirely. This will allow the page to load dynamically, identify the visitor and set the cookies.
  2. Second and subsequent visits. One or more of the cookies are set. Append them to the URL requested by the visitor to generate the cache key. This will effectively create a copy of the content for each combination of the URL and the value of each cookie, and ensure that each visitor sees the content that applies to him.

Notes

In all cases in which caching has to be disabled, it's possible to keep caching of static content enabled. For example, caching can be used to minify JavaScript and CSS, thus reducing the amount of HTTP requests sent to the server, speeding up the page.


You can purchase our internationalisation solutions from our online shop.