JSP page cache Technology-browser cache introduction and implementation

Source: Internet
Author: User
Tags browser cache microsoft frontpage

I. Overview
The cache idea can be applied to all layers of software hierarchy. It is an internal mechanism that is imperceptible to the outside world.
The database itself has a cache, And the persistence layer can also be cached. (For example, hibernate also has cache levels 1 and 2)
The business layer can also have a cache (but in general, this is a process domain, and no cache is set ).
The presentation layer/data service layer (the traditional web presentation layer) can also set the cache (jsp cache is the layer to implement the cache mechanism on the app server)
In addition, Browser also has cache (such as IE), which is also known to all (implementing the cache mechanism on web server ). The higher the upper-layer cache, the better the effect, the more profound the lower-layer cache.

Ii. cache implementation (the browser caches the currently accessed JSP dynamic pages)
(1) server Method:Copy codeThe Code is as follows: <%
Response. setHeader ("Pragma", "No-cache ");
Response. setHeader ("Cache-Control", "no-cache ");
Response. setDateHeader ("Expires",-10 );
%>

(2) Client Methods:
Meta is used to simulate HTTP Response Header packets in HTML documents. Meta Tags are used in Name attribute
1. <meta name = "Generator" contect = ""> describes generation tools (such as Microsoft FrontPage 4.0;
2. <meta name = "KEYWords" contect = ""> describe KEYWords Of Your webpage to search engines;
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 creator of your site;
5. <meta name = "Robots" contect = "all | none | index | noindex | follow | nofollow">
The attributes are described as follows::
Set to all: the file will be retrieved, and the link on the page can be queried;
Set to none: files will not be retrieved, and links 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: files will not be retrieved, and links on the page can be queried.
Http-equiv attributes
1. <meta http-equiv = "Content-Type" contect = "text/html"; charset = gb_2312-80 ">
And <meta http-equiv = "Content-Language" contect = "zh-CN"> are used to describe the text and Language used by the Home Page. For example, if English is a 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"> regularly redirect a webpage to http within the specified time; // yourlink;
3. <meta http-equiv = "Expires" contect = "Mon, 12 May 2001 00:20:00 GMT"> you can set the expiration time of a webpage, once it expires, it must be called again on the server. Note that the GMT time format must be used;
4. <meta http-equiv = "Pragma" contect = "no-cache"> is used to disable the browser from accessing the page content from the cache of the local machine, once the page is set, it cannot be called out from the Cache;
5. <meta http-equiv = "set-cookie" contect = "Mon, 12 May 2001 00:20:00 GMT"> cookie setting: If the webpage expires, the cookie on the disk will be deleted. Note that the GMT time format must be used;
6. <meta http-equiv = "Pics-label" contect = ""> webpage rating: There is a content setting in internet Options of IE, it can prevent browsing of some restricted websites, and the website's restricted level is set through the meta attribute;
7. <meta http-equiv = "windows-Target" contect = "_ top"> force the page to be displayed on an independent page in the current window, it can prevent your webpage from being called as a frame page by others;
8. <meta http-equiv = "Page-Enter" contect = "revealTrans (duration = 10, transtion = 50) "> and <meta http-equiv =" Page-Exit "contect =" revealTrans (duration = 20, transtion = 6) "> set the special effect when you enter and Exit the Page, this function is called "format/Webpage transition" in FrontPage, but the page to be added cannot be a frame page.
Iii. cache applications
(1) Prevent JSP page caching in order to prevent the browser from caching the currently accessed JSP dynamic page, you can set it as follows:
<%
// Set the expiration date to a previous time
Response. setHeader ("Expires", "Sat, 6 May 199512: 00: 00 GMT ");
// Set the HTTP/1.1 no-cache Header
Response. setHeader ("Cache-Control", "no-store, no-cache, must-revalidate ");
// Set the IE extension HTTP/1.1 no-cache headers. You can add
Response. addHeader ("Cache-Control", "post-check = 0, pre-check = 0 ");
// Set the standard HTTP/1.0 no-cache header.
Response. setHeader ("Pragma", "no-cache ");
%>
Of course, the Code contained on every page is cumbersome. You can use the custom Filter method to process related pages.
(2) Clear page cache in jsp and html
1. disable Client caching by adding the following content in Copy codeThe Code is as follows: <META HTTP-EQUIV = "pragma" CONTENT = "no-cache">
<META HTTP-EQUIV = "Cache-Control" CONTENT = "no-cache, must-revalidate">
<META HTTP-EQUIV = "expires" CONTENT = "Wed, 26 Feb 199708: 21: 57 GMT">

OrCopy codeThe Code is as follows: <meta http-equiv = "pragma" content = "no-cache">
<Meta http-equiv = "cache-control" content = "no-cache">
<Meta http-equiv = "expires" content = "0">

2. Disable caching on the dynamic web page of the server. Add a script similar to the following:Copy codeThe Code is as follows: response. setHeader ("Pragma", "No-cache ");
Response. setHeader ("Cache-Control", "no-cache ");
Response. setDateHeader ("Expires", 0 );

(3) set a limited time Cache Copy codeThe Code is as follows: 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

Supplement: several suggestions on. jsp cache:
1. jsp cache is best implemented on the filter, and the pages to be buffered are concentrated in the same directory. You only need to modify web. xml to complete the buffer settings for each change, which is more convenient.
2. Gzip compression can compress the page very small, with an average compression ratio of 1/3. The HashMap buffer of jsp cache compresses the page, which definitely saves more memory consumption and is more efficient than before compression.

Related Article

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.