[plt-scheme] Browser caching servlet generated pages

From: Jacob Matthews (jacobm at cs.uchicago.edu)
Date: Mon Nov 3 09:23:25 EST 2003

Eli Barzilay wrote:

>On Nov  2, Noel Welsh wrote:
>  
>
>>Is there some header that I could return to prevent
>>caching?  Alternatively are there other techniques
>>people are familiar with?
>>    
>>
>
>In my server I use:
>
>  (add-output-header 'Cache-Control "no-cache")
>  (add-output-header 'Pragma "no-cache")
>  (add-output-header 'Expires (*date-gmt-string*))
>
>which seemed to work with all browsers at the time.
>  
>
I use essentially this same mechanism, but there's a subtlety: we found 
that if you're using the PLT Server's interactivity features, it's best 
to disable caching only on the very first page of the interaction. 

If a browser caches a page associated with the base URL for your servlet 
(myserver/servlets/myservlet.ss or whatever), you'll probably end up 
with a servlet that appears to work the first time but dies the second 
time; when you go to the root page the second time, you get a cached 
page with an expired continuation URL and you'll always get a timeout 
message when you try to resume the computation.  On the other hand, all 
the subsequent pages are better off cached: their URLs are globally 
unique, so you're in no danger of an expired cached page interfering 
with a still-valid computation, and if you disable caching it'll make it 
harder for users to use their back, forward, and clone buttons.

My solution to this problem was to have a "send/no-cache" function that 
disabled caching and calling that function on the first page, but it'd 
be nice if disabling caching for the first page a servlet sends were the 
web server's default behavior.

-jacob



Posted on the users mailing list.