Keeping Content From Caching

The tags below are what I use to keep dynamic data from being cached:

<cfheader name=”Cache-Control” value=”no-store” />
<cfheader name=”Pragma” value=”no-cache” />
<cfheader name=”Expires” value=”Tue, 16 Oct 1973 00:00:00 GMT” />

(The value of the “Expires” header is not some magical date — it can be any date in the past. I usually use my birthday, just for fun.)

These headers address client-side caching (caching by the browser), and server-side caching (proxy servers that do caching, like those used by AOL). The “Pragma” tag is a little obsolete and has been replaced by the “Cache-Control” tag in HTTP 1.1, but I keep it in there just to be safe. These tags go at the top of my Application.cfm file, just below the CFAPPLICATION tag. So far, I have had pretty good luck with them, and they go in just about every application I write.

For more information on how AOL handles proxy server caching (something all web developers need to be aware of), check out this document published by AOL.

5 Responses to Keeping Content From Caching

  1. Todd says:

    Hrmmmm… I’m Oct 7th, same here. Didn’t realize we were the same age. 🙂

  2. PaulWeston says:

    A while ago I used code like this but there were issues with some browsers. I can’t find the reference (stating which browsers were affected) but remember what the solution was: create another ‘head’ section at the foot of the page with the same information. Oh, got it, it’s coming back to me now. It’s something about whether the size of the page is less than a certain KB size in IE. Weird.The guaranteed refresher of pages (I use it over any other method nowadays) is to use a unique id tag when calling a page. I tag a UID= onto the URL and whack a CF UID onto it. It solved everything on an intranet solution where nothing (including your fix) seemed to work. The joys of working with IE, eh. I learned the uid method from the Flash forums where the big problem is ensuring fetched data is not actually old data (which does happen).

  3. PaulWeston says:

    Found the link to the caching problem in IE:

  4. hosey says:

    I ran into a major issue with IE and the pragma code using https and flash. With the pragma code in it worked in our test enviroment for 24 hours; it began erroring after that. What would happen was this:If you typed the url in the browser would get the correct results, however flash could not load those results. The pragma code, in a secure enviroment, wasnt allowing the page to be in the cache at all and so flash couldnt read it. At least that is my assumption of what was occurring.

  5. pixelEngine says:

    So I have this same problem! The swf loads the xml great under all Mozilla browsers but fails under IE5 and 6. (damn you m$ )How in god’s name can this be resolved? I have searched for hours on this issue and I keep hearing “policy files” … but that can’t be the case if its workng just fine under mozilla. And not to mention that I am not doing anything “cross” domain…. I am simply pulling xml from and using it in the swf on the secured page at ideas??!! My only option will be to abandon Flash pretty soon if we can’t resolve this stupid lil’ thing! yikes.Tnx!