<!-- --><style type="text/css">@import url(https://www.blogger.com/static/v1/v-css/navbar/3334278262-classic.css); div.b-mobile {display:none;} </style> </head><body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar.g?targetBlogID\x3d7256432\x26blogName\x3dThe+Frustrated+Programmer\x26publishMode\x3dPUBLISH_MODE_BLOGSPOT\x26navbarType\x3dBLACK\x26layoutType\x3dCLASSIC\x26searchRoot\x3dhttp://frustratedprogrammer.blogspot.com/search\x26blogLocale\x3den_US\x26v\x3d2\x26homepageUrl\x3dhttp://frustratedprogrammer.blogspot.com/\x26vt\x3d5012862196962223429', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe" }); } }); </script>
| Monday, July 19, 2004

To be honest, all the web applications I've written so far have always disabled page caching. But even though this application has multiple users that access the same data concurrently, they business owners wanted to turn on page caching. I agree that the back button warning from IE is really annoying, but I let them know some of the issues that go along with caching, and we agreed to give it a try.

After playing around a bit, we figured the behavior we wanted was that any page forward movement (form submit or link click) should get a new page from the server, while the back and forward buttons should use the browser's cache (to avoid the annoying message from the brwoser). There was one catch, they wanted the cache to expire after a set amount of time. I couldn't figure it out. Is there some setting I'm missing? The only way to make the back button cache, and link clicking not cache is to use the browser's detault behavoir. But then the duration of the cache is control usually be disk space, set on the browser.

I constructed the table below to document the behavoir of IE vs. Mozilla with the different caching methods. The three methods I tried were:
-Default Caching (DC)- This is what ever the browser does by default. No special headers were sent.
-Caching Disabled (CD)- The following headers were sent:
  response.setHeader( "Cache-Control", "no-cache" );

response.setDateHeader( "Expires", -1 );
response.setHeader( "Pragma", "No-cache" );

-Some Caching (SC)- Pages are only active for a set amount of time, in this case one minute. The following headers were sent:
  response.setHeader( "Cache-Control", "max-age=" + (1*60) +", must-revalidate" );


Browser/CachingForm PostForm GetLinkBackForwardReload
IE - DC---XXX
IE - CD------
IE - SC--(?)XXXX
Moz - DC---XXX
Moz - CD------
Moz - SC-XXXXX

(X indicated page was retrieved from cache, not the server)
(? Strange but true. IE treats a form GET different than a link GET)

This is the page I used to test things:

<%@ page import="java.util.Date"%>
<%
/*
response.setHeader( "Cache-Control", "no-cache" );
response.setDateHeader( "Expires", -1 );
response.setHeader( "Pragma", "No-cache" );
*/
//response.setHeader( "Cache-Control", "max-age=" + (1*60) +", must-revalidate" );
%>

Time: <%= System.currentTimeMillis() %> <%= new Date()%> <br />
<form taget="/commsales/cache-test.jsp" method="post">
Foo: <input type="text" name="foo" /><br />
<input type="submit" value="Submit Post" />
</form>

<form taget="/commsales/cache-test.jsp" method="get">
Bar: <input type="text" name="bar" /><br />
<input type="submit" value="Submit Get" />
</form>

<a href="/commsales/cache-test.jsp">Link</a>