Cache caching technology for JSP pages--Introduction and implementation of browser caching _jsp programming

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 has a cache, and the persistence layer can also be cached. (For example: Hibernate, also divided into 1 levels and 2 cache)
The business layer can also have caching (but generally, this is a process domain and does not set a cache).
Performance layer/Data service layer (traditional Web performance layer) can also set caching (JSP cache is this layer, implementation of the caching mechanism on the app server)
In addition, browser also has caching (IE) that everyone knows (implementing caching mechanisms on the Web server). The higher the cache effect, the more far-reaching the bottom cache effect.

Second, cache implementation (browser cache current Access JSP dynamic page)
(i), service-side method
Copy Code code as follows:

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

(ii), client-side methods
Meta is a response header message that is used to simulate an HTTP protocol in an HTML document. Meta tags are used in Name Property
1, <meta name= "generator" contect= "" to describe the build tools (such as Microsoft FrontPage 4.0);
2, <meta name= "KEYWords" contect= "" to the search engine to explain the keywords of your web page;
3, <meta name= "DEscription" contect= "" to tell search engine your site's main content;
4, <meta name= "Author" contect= "Your name" > Tell the search engine your site's production of the author;
5, <meta name= "Robots" contect= "All|none|index|noindex|follow|nofollow"
the properties are described below
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: file will be retrieved;
Set to follow: the link 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" and "charset=gb_2312-80"
and <meta http-equiv= "Content-language" contect= "ZH-CN" to explain the text and language used in the production of the home page, as well as the iso-8859-1 character set, BIG5, Utf-8, Shift-jis, Euc, Koi8-2 and other character sets;
2, <meta http-equiv= "Refresh" contect= "N;url=http://yourlink" to make 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, once expired must be called back 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, set once away from the Web page can not be removed from the cache;
5, <meta http-equiv= "Set-cookie" contect= "mon,12 May 2001 00:20:00 GMT" >cookie set, if the page expires, save the cookie will be deleted. Attention must also be paid to the use of GMT time format;
6, <meta http-equiv= "Pics-label" contect= "" "> Web rating, in IE Internet Options, there is a content settings, you can prevent browsing some restricted sites, and the site's limit level is through the meta attribute to set;
7, <meta http-equiv= "Windows-target" contect= "_top" to 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)" Sets the special effect of entering and leaving the page, which is the "Format/page transition" in FrontPage, but the page you add cannot be a frame page.
third, caching applications
(a), to prevent JSP page caching to prevent browsers from caching the current Access JSP dynamic page, you can set the following way:
<%
Set the expiration date to a past time
Response.setheader ("Expires", "Sat, 6 May 199512:00:00 GMT");
Set http/1.1 No-cache Header
Response.setheader ("Cache-control", "no-store,no-cache,must-revalidate");
Set IE extensions http/1.1 no-cache headers, users add them 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 is very cumbersome, you can customize the filter (filter) method to deal with related pages
(ii), jsp,html clear page Cache
1. Prohibit client caching to include a similar content in
Copy Code code 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, Feb 199708:21:57 GMT" >

Or
Copy Code code 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 in the server's Dynamic Web page to include scripts similar to the following
Copy Code code as follows:

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

(iii) Setting a limited-time cache
Copy Code code 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

add: A few suggestions about. JSP Cache:
1.jsp Cache is best to do on the filter, the need to buffer the page in the same directory, each change only need to change web.xml can complete the buffer settings, which is more convenient.
2.Gzip compression can compress the page very small, the average compression ratio is 1/3,jsp cache of HashMap buffered compressed pages, certainly more than before not compressed memory consumption, and more efficient.
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.