Explanation of this header cache code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #1

    Explanation of this header cache code

    <%response.addH eader("Pragma", "No-cache");
    response.addHea der("Cache-Control", "no-cache");
    response.addDat eHeader("Expire s", -1);
    %>


    what is the purpose of this code ...


    plz explain me in details ....


    thanx in advance .....
  • abctech
    New Member
    • Dec 2006
    • 157

    #2
    Originally posted by dmjpro
    <%response.addH eader("Pragma", "No-cache");
    response.addHea der("Cache-Control", "no-cache");
    response.addDat eHeader("Expire s", -1);
    %>


    what is the purpose of this code ...


    plz explain me in details ....


    thanx in advance .....
    Hello,
    At the top of every JSP the above header attributes are used to prevent caching.
    Now I don't know in depth about 'Caching' but whatever little I know I'll share it with you, for the details we'll have to wait for an expert opinion :)

    Well,
    Http headers used for cache control to prevent the web pages from being cached by the browser and proxy server.

    response.setHea der("Cache-Control","no-cache"); //prevents disk caching (HTTP 1.1)
    response.setHea der("Pragma","n o-cache"); //prevents disk caching (HTTP 1.0)
    response.setDat eHeader ("Expires", 0); //prevents caching at the proxy server

    I'm not really sure about response.addDat eHeader("Expire s", -1);
    I think its to be used for web pages which have information subject to change promptly, such pages do remain in the disk cache of the IE to be used when the user hits back/forward but when the user actually sends a request for such a page the browser fetches the updated version from the web server.

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      lot of thanx

      well ...

      i think response.addHea der("Expires",-1) means that the cache control prevention for only that browsing session ..

      as early as the browsing session exits then the cache control starts again

      am i right ...

      manyyyyy thanx again

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        I will just say that in response.addHea der("Expires",-1)

        -1 is the expiration time. The value -1 means that there is no expiration time set.

        Comment

        • dmjpro
          Top Contributor
          • Jan 2007
          • 2476

          #5
          thanx for ur reply ......

          one more thing i want to know that where the cache happens ...

          i mean does it happen in local memory or into the disk

          my problem occures as long as the same browsing session remains..
          after the browsing sessoin ends then the updated page shown

          plz help me out ...
          again thanx in advance

          Comment

          • abctech
            New Member
            • Dec 2006
            • 157

            #6
            Originally posted by dmjpro
            thanx for ur reply ......

            one more thing i want to know that where the cache happens ...

            i mean does it happen in local memory or into the disk

            my problem occures as long as the same browsing session remains..
            after the browsing sessoin ends then the updated page shown

            plz help me out ...
            again thanx in advance
            I think its the disk, isn't our surfing history stored in those 'History','Temp orary Internet Files' and some other such temporary folders on our hard drive?

            P.S:
            By the way, can I ask you in which class/interface is the addDateHeader(S tring,int) method located?

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Originally posted by abctech
              By the way, can I ask you in which class/interface is the addDateHeader(S tring,int) method located?
              javax.servlet.h ttp.HttpServlet Response

              Comment

              • abctech
                New Member
                • Dec 2006
                • 157

                #8
                Originally posted by r035198x
                javax.servlet.h ttp.HttpServlet Response
                Thanks,
                Got it.

                Interface- 'HttpServletRes ponse'
                public void addDateHeader(j ava.lang.String name,long date);

                dmjpro-
                Here's a link I just came across regarding preventing caching of web pages(but its only for IE)

                Comment

                • dmjpro
                  Top Contributor
                  • Jan 2007
                  • 2476

                  #9
                  thanx a lot ....

                  Comment

                  Working...