Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Stop caching of an image

 
Harry Brearley
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I need to stop caching of an image in a page. I generate a new image each time the page is viewed, by calling a servlet as the source of the <img tag.
The rest of the page is OK to be cached for longer.
Is this possible? I have tried setting the following in the servlet:
response.addHeader("Pragma", "NoCache");
response.addHeader("Cache-Control", "no-cache");
response.addDateHeader("Expires", 1);

Seems to have zero effect. I am testing using latest firefox browser, locally on my m/c so i can guarantee no proxy caching inbetween server and client.

thank you for any help
Harry
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I do is to override the getLastModified(request) method in the servlet that returns the image. In your case you could do something simple like returning System.currentTimeMillis().
 
Harry Brearley
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the really fast response. I have tried this but the behaviour does not seem to have changed. Do you have this working insider an img statement. Here is mine:

<img src="${context}/sp?spId=${spId}" alt="" />

Above is from my .jsp file

/sp maps to my servlet in web.xml

Perhaps i am missing something else?
 
Harry Brearley
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also tried putting the
<%
response.addHeader("Pragma", "NoCache");
response.addHeader("Cache-Control", "no-cache");
response.addDateHeader("Expires", 1);
%>
at the top of the jsp page and keeping the overridden getLastModified(request) method in the servlet.

Same behaviour

I must be missing something?
 
Rusty Smythe
Ranch Hand
Posts: 93
Mac Objective C Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might try the items referenced in the JSP FAQ: NoCacheHeaders.
[ August 11, 2006: Message edited by: Rusty Smythe ]
 
Harry Brearley
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am starting to think there is not an answer for this. It seems when i hit the back button in the browser (testing with firefox) there is no communication with the web server. When i hit the forward button the same.
When i click on a link (like a hit) then it seems to fetch
?
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't particularly see what's wrong with allowing the back and forwards buttons to use data from the cache, at least in GET mode. It's quite possible that whatever HTTP spec Firefox is implementing permits that. But I would expect that clicking on a link should work correctly, and it sounds like you are saying it does work correctly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic