Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to clear the cache in JSF?  RSS feed

 
Sumeet Singh Aryan
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I want to clear the cache in JSF i tried the following code but still the problem is not solved.

FacesContext facesContext = event.getFacesContext();
HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Cache-Control", "no-store");
response.setHeader("Cache-Control", "must-revalidate");
response.setHeader("Expires","Mon, 8 Aug 2006 10:00:00 GMT"); // some date in the past

i write the above code in PhaseListener#beforePhase. still it's not worling
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The setHeader() overrides any previously set header on the same name. You need addHeader() when you want to add header values for the same header name. You can also set the header values commaseparated using only one setHeader().

After all, you just need cache-control="no-cache" for this. All the other cache-control settings are superfluous when the "no-cache" is set. Here's the complete and correct set:



Don't forget to clear the browser cache before testing.
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot clear the user's cache via a server-initiated action. That kind of activity is what malware does.

What you have been doing is instructing the browser not to cache the results you're returning - something you'd normally do when returning pages whose content is subject to change.

Ordinarily, you don't do this when using JSF, since the whole point of JSF is to provide pages with non-static content. Thus, the JSF framework suppresses caching automatically.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!