3

i tried a lot of possible solutions but i can't solve the problem:

<meta http-equiv="Cache-control" content="no-cache">
<meta http-equiv="Cache-control" content="no-store">
<meta http-equiv="Cache-control" content="must-revalidate">
<meta http-equiv="pragma" content="no-cache"> 
<meta name="expires" content="0">

these are not working. Can anybody help? I am using jsp/servlet. And application is a portlet for websphere portal 6.1.

rdn
  • 45
  • 1
  • 5
  • I believe you should answer BalusC's answer below. It works for resources. The only thing besides that affecting portlets would be the portlet specific cache settings that you set up using the administrative interfaces. – user918176 Sep 17 '11 at 22:13

5 Answers5

2

Never rely on meta tags in an HTML page to control caching. Instead you need to set the HTTP headers in your response. In your controller before you display any output you will want to set the following:

response.setHeader("Cache-Control", "max-age=0, must-revalidate");

This has worked for me in the past but you may also like to try the following if that doesn't do the trick

response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 1);
Mistu4u
  • 4,475
  • 13
  • 44
  • 80
Brad
  • 13,946
  • 10
  • 56
  • 71
1

The meta headers are only used when the page is requested from the local disk file system instead of over HTTP. You need to set the real HTTP response headers instead.

Create a filter which does basically the following job:

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
    HttpServletResponse hsr = (HttpServletResponse) res;
    hsr.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
    hsr.setHeader("Pragma", "no-cache"); // HTTP 1.0.
    hsr.setDateHeader("Expires", 0); // Proxies.
    chain.doFilter(req, res);
}

Map it on an URL pattern of for example *.jsp to get it to run on all JSP pages.

You had it right with the Cache-Control headers in your original question, it's mandatory to have no-store and must-revalidate along no-cache. Almost all other answers posted as far are basically MSIE targeted.

See also:

Community
  • 1
  • 1
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
0

Try setting those in the response header in your servlet like,

response.setHeader("Cache-Control", "no-cache");
response.setHeader("Cache-Control", "no-store");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0);
Dilini Rajapaksha
  • 2,190
  • 3
  • 27
  • 38
0

Firefox 3 is known for it's cache problems

https://bugzilla.mozilla.org/buglist.cgi?quicksearch=Cache-control

I once implemented a solution where every page would get a random ID added to it's name, so Firefox thinks it's a different page. Don't know much about portlets, but have you tried that?

Jeroen Baert
  • 1,233
  • 2
  • 12
  • 28
0

we had similar problems with Liferay Portal Server. Our solution was to add a timestamp to the link of the resources (css/js), something like

/mysite/css/menu.css?t=1291218768531

We control when we refresh the timestamp from within our application, so we have control when we force the browser to reload the resource.

Sylar
  • 2,134
  • 2
  • 16
  • 26
  • i need reload a form element. I put a dynamic parameter to form's actionurl but it did not work. Then i convert form method to get from post. After submitting i am changing parameters from url then enter, but still same content coming!! Do you have any idea? – rdn Jun 24 '11 at 13:31