Using Oscache to Improve program performance

Source: Internet
Author: User

I. INTRODUCTION

Oscache is a broad-based, high-performance Java EE caching framework that can be applied to a common caching solution for any application in the JavaScript.


Two. Features

1. You can cache any object, you can cache portions of JSP pages or HTTP requests without restriction, and any Java object can be cached

2. Can be permanently cached, because the cache can be arbitrarily written to the hard disk

3. Support Cluster

4. You can control the expiration of cached objects


Three. Use

1. Caching of local pages

<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%><%@ taglib uri= "/http Www.opensymphony.com/oscache "prefix=" Cache "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
2. Caching the entire page

<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%><%@ taglib uri= "/http Www.opensymphony.com/oscache "prefix=" Cache "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
3. Cache Objects

public class Cacheservlet extends HttpServlet {private static final long serialversionuid = 1l;protected void Doget (httpse Rvletrequest request, HttpServletResponse response) {int refreshperiod = ten;//cache in 6 Secondsgeneralcacheadministrato R cache = new Generalcacheadministrator (); try {//Get data from cachedate mydate = (Date) cache.getfromcache ("MyDate", ref Reshperiod); System.out.println ("Current date is:" + mydate);}  catch (Needsrefreshexception e) {try {date mydate = new Date ();//Put data into Cachecache.putincache ("MyDate", mydate);} catch (Exception ex) {cache.cancelupdate ("mydate");}}}
oscache.properties

Web. XML

<?xml version= "1.0" encoding= "UTF-8"? ><web-app xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns= "Http://java.sun.com/xml/ns/javaee" xmlns:web= "http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi: schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id= "Webapp_ ID "version=" 2.5 "><filter><filter-name>CacheFilter</filter-name><!-- Cachefilter only captures page requests with HTTP headers of 200, which are only cached for error-free requests--><filter-class> com.opensymphony.oscache.web.filter.cachefilter</filter-class><init-param><!--the time period in which the content is cached, in seconds, The default is 3,600 seconds--><param-name>time</param-name><param-value>10</param-value></ init-param><init-param><param-name>scope</param-name><param-value>application</ param-value></init-param></filter><!--Cache All the cache.jsp file--><filter-mapping> <filter-name>cachefilter</filter-name><url-pattern>/cache2.jsp</url-pattern></filter-mapping><servlet><servlet-name>cacheservlet</servlet-name ><servlet-class>com.zdp.cache.cacheservlet</servlet-class></servlet><servlet-mapping ><servlet-name>cacheServlet</servlet-name><url-pattern>/cacheServlet</url-pattern> </servlet-mapping><welcome-file-list><welcome-file>cache1.jsp</welcome-file></ Welcome-file-list></web-app>
four. Core Api-generalcacheadministrator:

1.void Putincache (String key,object content);//put on Object in a cache

2.Object Getfromcache (String key);//Get on Object from the Cache

3.void removeentry (String key);//Remove an Object in a cache

4.void flushentry (String key);//Flushes a single cache entry

5.void Flushall ();//flush the entire cache immediately

6.void CancelUpdate (String key);//Cacels a pending cache update

Participant Information: http://www.cnblogs.com/huzi007/p/3873396.html

Using Oscache to Improve program performance

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.