JSP page cache and Clear cache

Source: Internet
Author: User
Tags browser cache microsoft frontpage

I. Overview

The idea of caching can be applied at all levels of software layering. It is an internal mechanism that is not perceptible to the outside world.

The database itself is cached, and persistent layers can be cached. (e.g. hibernate, 1-and 2-level caches)

The business layer can also have a cache (but in general, this is a process domain and will not be cached).

The presentation layer/Data Service layer (the presentation layer of the traditional web) can also set the cache (the JSP cache is the layer that implements the caching mechanism on the app server)

Browser also has a cache (ie, for example) that everyone knows (implementing a caching mechanism on the Web server). The better the cache effect on the upper level, the more profound the underlying cache impact.

Second, the cache implementation (browser cache currently accessed JSP dynamic page)

(a), the service-side method:

<%
Response.setheader ("Pragma", "No-cache");
Response.setheader ("Cache-control", "No-cache");
Response.setdateheader ("Expires",-10);
%>
(b), client method:

Meta is the response header message used to simulate an HTTP protocol in an HTML document. Meta tags are used in Name property
1, <meta name= "Generator" contect= "" to illustrate the generation tools (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= "" to 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, as well as the iso-8859-1 character set in English, 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 once it expires, it must be recalled to the server. 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 content of the page, after the settings 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" "" "" "> page rating, Internet Options in IE has a content setting to prevent browsing some restricted sites, and the site's limit is set by the meta-attribute;
7, <meta http-equiv= "Windows-target" contect= "_top" > Force the page in the current window with a separate page display, you can prevent their own web page by others as a frame page call;
8, <meta http-equiv= "Page-enter" contect= "Revealtrans (duration=10,transtion= 50)" > and <meta http-equiv= "Page-Exit" Contect= "Revealtrans (duration=20,transtion =6)" To set the special effect when entering and leaving the page, which is the "Format/page transition" in FrontPage, but the added page cannot be a frame page.

Third, the cache application

(a), Prevent JSP page cache in order to prevent the browser from caching the currently accessed JSP dynamic page, you can set the following way:
<%
Set the expiration date to a past time

Response.setheader ("Expires", "Sat, 6 May 1995 12:00:00 GMT");

Set http/1.1 No-cache Header
Response.setheader ("Cache-control", "no-store,no-cache,must-revalidate");

Set IE extension http/1.1 no-cache headers, users add themselves
Response.AddHeader ("Cache-control", "post-check=0, pre-check=0");

Sets the standard http/1.0 No-cache header.
Response.setheader ("Pragma", "No-cache");
%>

Of course, each page contains this code, which can be cumbersome to handle related pages by means of a custom filter

(b), jsp,html clear page cache

1. Disable client-side caching to add a similar following to
<meta http-equiv= "Pragma" content= "No-cache" >
<meta http-equiv= "Cache-control" content= "No-cache, must-revalidate" >
<meta http-equiv= "Expires" Content= "Wed, 1997 08:21:57 GMT" >

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

2. Disable caching in the Dynamic Web page of the server, add a script similar to the following

Response.setheader ("Pragma", "No-cache");
Response.setheader ("Cache-control", "No-cache");
Response.setdateheader ("Expires", 0);

(iii) Setting the cache for a limited time

int minutes = 10;

Date d = new Date ();

String moddate = d.togmtstring ();

String expdate = null;

Expdate = (New Date (D.gettime () + minutes * 60000)). toGMTString ();

Response.setheader ("last-modified", moddate);

Response.setheader ("Expires", expdate);

Response.setheader ("Cache-control", "public"); http/1.1

Response.setheader ("Pragma", "Pragma"); http/1.0

Add: A few suggestions about the. JSP cache:

1.jsp Cache is best done on the filter, the need to buffer the page in the same directory, each change only need to change the Web. XML to complete the buffer settings, it is more convenient.

2.Gzip compression can compress the page very small, the average compression ratio for the 1/3,jsp cache HashMap buffer compressed pages, is certainly more than uncompressed before the memory consumption, and more efficient. For gzip reference this open source project:/http Sourceforge.net/projects/pjl-comp-filter

See: JSP page cache Settings

JSP page cache and Clear cache

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.