or send us a message

Magento Enterprise Pagecache Cart/Currency Issue

Written by: Simon Smith, On: Wednesday 2nd September 2015

A cautionary tale! While working on an Enterprise website already loaded with multiple stores and modules from a previous developer, I noticed that with EE FPC enabled switching currency or adding to basket (remain on page) didn't always update the appropriate page assets until you hard refreshed the browser.

My immediate thought was it must be a module clash - and so enabled debugging and noticed some core blocks where being rewritten - such as cart_sidebar. Eureka I thought! and went ahead disabling some of the non EE friendly modules in the site and double checking all the template block declarations were correct.

I remembered to check what I should have checked in the first place...

Sadly, none of these endeavours solved the problem, and the behaviour remained until I remembered to check what I should have checked in the first place - htaccess!

I must admit it's been a while since I've worked on an Apache based Magento instance as we always use NginX and php-fpm for Magento, but that's still no excuse.

As suspected, I found the offending line in htaccess that was causing the woes;


## http://developer.yahoo.com/performance/rules.html#expires

    ExpiresActive On
    ExpiresDefault "access plus 1 year"


This tells the web browser to cache all available assets it downloads from the url and keep them for a year. With FPC on, the page is presented to the browser as an html document, so it saves it to show the user the next time they hit the same url, thinking the content won’t change for a year. This causes problems with basket totals, currency switching etc. as the browser thinks it can continue serving the locally cached version. Usually a browser refresh will correct it, but it’s pretty rotten user experience.

Instead, you need to selectively tell the browser what is safe to cache for a reasonable period and set html to cache for only a second (or disable altogether), to ensure the dynamic parts of the page get loaded correctly;


ExpiresActive On 

## SET HTML CACHE TO 1 SECOND
ExpiresByType text/html "access plus 1 second" 

## All other assets can afford a longer shelf life – don’t forget a browser refresh will update them anyway
ExpiresByType image/jpg "access 1 year" 
ExpiresByType image/jpeg "access 1 year" 
ExpiresByType image/gif "access 1 year" 
ExpiresByType image/png "access 1 year" 
ExpiresByType text/css "access 1 month" 
ExpiresByType application/pdf "access 1 month" 
ExpiresByType text/x-javascript "access 1 month" 
ExpiresByType application/x-shockwave-flash "access 1 month" 
ExpiresByType image/x-icon "access 1 year" 
ExpiresDefault A0

Magento is a complex and comprehensive beast, but never forget to check the basic environmentals first.

Pixie Media

We are a Devon's first and only Magento Partner Agency. With over 18 years experience, we offer complete digital solutions to ecommerce clients across the globe.

Magento Business Partner
Pixie Media - Devon's first Magento Partner Agency
Certified Magento Developers
We Specialise In;