Sometimes, you find little quirks that Google doesn’t seem to find the answer. Today was one of those quirks. I’ve been building a public site that is accessed via a link emailed to a customer. The link is only good for one use – once it is visited, the access code becomes invalid. In my testing, everything worked well – I’d visit the page, refresh the browser and an error page would be displayed. Perfect. The problem came in when testing using the email links. In Chrome, I found that if I followed the link from my email, the link would work multiple times. I pulled up Chrome Developer Tools and found that the entire page was being loaded from cache – Salesforce was never even being hit! If I refreshed the browser or put my cursor in the address bar, then the request was going to Salesforce and I was getting expected results.
The solution to this is to use the cache attribute of the page tag. After adding cache=”true” to my page, Salesforce would be hit every time. Things like images and js files are still loaded from cache if possible, but setting cache to true forces any Apex controllers to run and check to make sure all is well.
In conclusion, in my situation I needed to turn off caching, but in others, it may make sense to have a faster public site to turn on caching. It will also reduce traffic on the site and avoid limits if your site is popular.