• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

how to clear the cache in JSF?

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Saloon Keeper
Posts: 26011
186
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
pie. tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic