Results 1 to 2 of 2
Like Tree1Likes
  • 1 Post By itswebin@gmail.com

Thread: Disable cache for just specifc directory

  1. #1
    vector_ever is offline Senior Member
    Join Date
    Jul 2013
    Posts
    188
    Rep Power
    7

    Default Disable cache for just specifc directory

    Hello,

    I have class to disable the cache for all pages in my project

    Java Code:
    package control;
    
    import javax.faces.context.FacesContext;
    import javax.faces.event.PhaseEvent;
    import javax.faces.event.PhaseId;
    import javax.faces.event.PhaseListener;
    import javax.servlet.http.HttpServletResponse;
    
    /**
     *disable die Cache in Web browser
     */
    
    public class CacheListener implements PhaseListener
    {
        @Override
        public PhaseId getPhaseId()
        {
            return PhaseId.RENDER_RESPONSE;
        }
     
        @Override
        public void afterPhase(PhaseEvent event)
        {
        }
     
        @Override
        public void beforePhase(PhaseEvent event)
        {
            FacesContext facesContext = event.getFacesContext();
            HttpServletResponse response = (HttpServletResponse) facesContext
                    .getExternalContext().getResponse();
            response.addHeader("Pragma", "no-cache");
            response.addHeader("Cache-Control", "no-cache");
            // Stronger according to blog comment below that references HTTP spec
            response.addHeader("Cache-Control", "no-store");
            response.addHeader("Cache-Control", "must-revalidate");
            // some date in the past
            response.addHeader("Expires", "Mon, 8 Aug 2006 10:00:00 GMT");
        }
    }
    and in faces-config.xml, added
    Java Code:
    <lifecycle>
            <phase-listener id="nocache">control.CacheListener</phase-listener>
        </lifecycle>

    Any way i want to disable the cache just for specific pages of specific pages under specific directory

    http://localhost:8080/Wirote/index must the cache be active
    but under edit folder must the cache be disabled
    http://localhost:8080/Wirote/edit/update.xhtml
    http://localhost:8080/Wirote/edit/display.xhtml
    http://localhost:8080/Wirote/edit/intro.xhtml

    all directory under edit must have no cache other wise the cache must be active

    how to do it??
    Last edited by vector_ever; 06-23-2014 at 11:57 PM.

  2. #2
    Join Date
    Apr 2014
    Location
    http://www.roytuts.com
    Posts
    51
    Rep Power
    0

Similar Threads

  1. Binary Cache
    By Collider in forum New To Java
    Replies: 10
    Last Post: 05-03-2012, 04:22 PM
  2. clear cache
    By Jadellll in forum New To Java
    Replies: 0
    Last Post: 03-20-2008, 09:27 AM
  3. JSP - using connection cache
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-30-2008, 09:54 AM
  4. BuffededImage cache
    By tim in forum New To Java
    Replies: 1
    Last Post: 01-24-2008, 12:00 AM
  5. cache problem in jsp
    By lpwing in forum JavaServer Pages (JSP) and JSTL
    Replies: 4
    Last Post: 01-15-2008, 07:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •