Friday 21 January 2011

Force reload of XML file - or prevent caching

I just spent a frustrating hour and a half on this.

I'm writing a simple page which updates an XML file. When I reloaded it after changing the data it showed up unmodified because the XML was cached. I spent ages trying various META tag stuff, maybe nonsense, as none of it worked.

I eventually stumbled upon the fact that it's a server issue. I'm working on a Apache local host. So adding the following to my httpd.conf:
# For XML
# Force reload
<FilesMatch "\.(xml|html)$">
Header set Cache-Control "max-age=60, public, must-revalidate"
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
</FilesMatch>
has done the trick. If I understand this correctly it will force a reload of the XML if it's more than 60 seconds since the last read. I'm not sure if that's what it really means - if anyone reads this and know's the answer I'd be grateful.

1 comment:

keep it nice now