Page cache and no cache settings

Source: Internet
Author: User
Tags microsoft frontpage

HTML HTTP protocol header information controls the page cache information in several places, including browser side, intermediate cache server side (such as squid, etc.), Web server side. This article discusses the caching situation in the intermediate cache server for HTML pages with cache control information in header information (Jsp/servlet is also generated as HTML pages).

The information header keywords in the HTTP protocol about caching include Cache-control (HTTP1.1), Pragma (HTTP1.0), Last-modified,expires, and so on.

      HTTP1.0 through pragma   controls the page cache, which you can set: Pragma or No-cache. There are a lot of articles on the internet to show how to control the browser or the intermediate cache server cache page, usually set the value of No-cache, but this value is not so insured, usually plus expires to achieve the goal. But if we deliberately need the browser or cache server to cache our page This value is set to Pragma.

HTTP1.1 Enable Cache-control to control the caching of pages or not, here are a few common parameters:

    • No-cache, neither the browser nor the cache server should cache the page information;

    • Public, both the browser and the cache server can cache page information;

    • No-store, request and response information should not be stored in the other's disk system;

    • Must-revalidate, for each request of the client, the proxy server must want the server to verify that the cache is outdated;

Last-modified only the last generation time of the page, GMT format;

Expires period limit, GMT format, refers to the browser or cache server at that point in time must be from the real server to obtain new page information;

The above two values in the JSP set the value to the character type GMT format, cannot take effect, sets the long type to take effect;

Here is a test example:

 package com.servlet;import java.io.IOException;import java.io.PrintWriter;import  javax.servlet.servletexception;import javax.servlet.http.httpservlet;import  Javax.servlet.http.httpservletrequest;import javax.servlet.http.httpservletresponse;public class  ServletA extends HttpServlet {     @Override      Public void service (httpservletrequest request, httpservletresponse response)              throws ServletException,  Ioexception {        response.setcontenttype ("text/html");         //servlet page default is non-cached         // This page allows caching on the browser side or cache server with a time limit of 20 seconds. Re-entering this page within         //20 seconds will not enter the servlet's          java.util.datE date = new java.util.date ();             response.setdateheader ("Last-modified", Date.gettime ())  //last-modified: Last Generation time of page           response.setdateheader ("Expires", Date.gettime () +20000);  // Expires: Obsolete term value          response.setheader ("Cache-control",  "  //cache-control to control whether the page is cached or not, public: both the browser and the cache server can cache page information;         response.setheader ("Pragma",  "Pragma");  //pragma: Sets whether the page is cached, Pragma is cached, No-cache does not cache          //does not allow the browser side or cache server to cache the current page information.         /*response.setheader (  "Pragma",  "No-cache"  );            response.setdateheader ("Expires",  0);            responSe.addheader (  "Cache-control",  "No-cache"  );//browser and cache server should not cache page information          response.addheader (  "Cache-control",  "No-store"  );//Request and response information should not be stored in the other's disk system;             response.addheader (  " Cache-control ", " must-revalidate " "; *///each request from the client, the proxy server must want the server to verify that the cache is stale;         system.out.println ("Into the servlet");         Response.getwriter (). Write ("Welcome to my homepage");     }    }

If you need to set no cache on the HTML page, add the following statement to the

1 <meta http-equiv= "pragma" content= "No-cache" >2 <meta http-equiv= "Cache-control" content= "No-cache" >3 <meta http-equiv= "Expires" content= "0" >

Attached: The role of Meta in HTML pages

Meta is the response header message used to simulate HTTP protocols in HTML documents. Meta tags are used in

  Name property

1, <meta name= "Generator" contect= "" > To illustrate the Build tool (such as Microsoft FrontPage 4.0), etc.;

2, <meta name= "KEYWords" contect= "" > to the search engine to explain the keywords of your page;

3, <meta name= "DEscription" contect= "" > Tell the Search engine the main content of your site;

4, <meta name= "Author" contect= "Your Name" > tell the Search engine the author of your site's production;

5, <meta name= "Robots" contect= "All|none|index|noindex|follow|nofollow" >

The properties are described as follows:

Set to all: The file will be retrieved and the link on the page can be queried;

Set to None: The file will not be retrieved, and the link on the page cannot be queried;

Set to index: The file will be retrieved;

Set to follow: links on the page can be queried;

Set to NOINDEX: The file will not be retrieved, but the link on the page can be queried;

Set to Nofollow: The file will not be retrieved and the link on the page can be queried.

  Http-equiv Property

1, <meta http-equiv= "Content-type" contect= "text/html"; charset=gb_2312-80 ">

and <meta http-equiv= "Content-language" contect= "ZH-CN" > to illustrate the text and language used in the production of the homepage;

Also such as English is iso-8859-1 character set, there are BIG5, Utf-8, Shift-jis, Euc, Koi8-2 and other character sets;

2, <meta http-equiv= "Refresh" contect= "N;url=http://yourlink" > Timing let the page in the specified time n, jump to the page http://yourlink;

3, <meta http-equiv= "Expires" contect= "mon,12 May 2001 00:20:00 GMT" > can be used to set the expiration time of the Web page and must be recalled to the server once it expires. It is important to note that the GMT time format must be used;

4, <meta http-equiv= "Pragma" contect= "No-cache" > is used to set the browser from the local computer cache to access the page content, set once left the page can not be recalled from the cache;

5, <meta http-equiv= "Set-cookie" contect= "mon,12 May 2001 00:20:00 GMT" >cookie set, if the page expires, the cookie will be deleted. It is also important to note that GMT time format must be used;

6, <meta http-equiv= "Pics-label" "contect=" "> Page rating, Internet Options in IE have a content setting, you can prevent browsing some restricted sites, The limit level of the website is set by the meta attribute;

7, <meta http-equiv=" Windows-target "contect=" _top "> force page Display in the current window as a separate page, You can prevent your Web page from being called by others as a frame page;

8, <meta http-equiv= "Page-enter" contect= "Revealtrans (duration=10,transtion=)" > and <meta http-equiv= " Page-exit "contect=" Revealtrans (duration=20,transtion=6) > Set special effects when entering and leaving the page, which is "format/page Transitions" in FrontPage, However, the added page cannot be a frame page.

Page cache and no cache settings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.