Oscache User Guide

xiaoxiao2021-03-06  93

Oscache is currently using the most wide cache scheme, JBoss, Hibernate, Spring, etc.

Let's take a brief introduction to the configuration and use of OSCache.

1. Installation process

Download the right OSCache version from http://www.opensymphony.com/oscache/download.html,

I downloaded the OSCache-2.0.2-Full version.

Unzip the downloaded file to the specified directory

Get the oscache.jar file from the decompression catalog to the / web-inf / lib or the corresponding library directory,

The JAR file name may contain version number and the release date information of this version, such as oscache-2.0.2-22jan04.jar

If your JDK version is 1.3.x, it is recommended to add a Commons-Collections.jar package of Apache Common lib in the lib.

If JDK is 1.4 or more

Get an OSCACHE.PROPERTIES file from the SRC or ETC directory, put it into the SRC root directory or publish environment / web-inf / class directory

If you need to create a disk cache, you must modify the cache.path information in oscache.properties (remove the previous # annotation).

WIN path is similar to c: // app // cache

UNIX class path Similar to / OPT / MyApp / Cache

Copy OSCache Tag Library File OSCACHE.TLD to / Web-INF / CLASSES directory.

Now your application directory is similar as follows:

$ Web_Application / Web-inf / lib / oscache.jar

$ Web_Application / Web-INF / CLASSES / OSCACHE.PROPERTIES

$ Web_Application / Web-INF / CLASSES / OSCACHE.TLD

Add the following code to the web.xml file

OSCACHE

/web-inf/classes/oscache.tld

In order to facilitate the debug log output, you must join Commons-Logging.jar and Log4j-1.2.8.jar to the current class library path

Add the following two log output profiles in the SRC directory:

Log4j.properties file content is:

Log4j.rootlogger = Debug, stdout, file

Log4j.appender.stdout = org.apache.log4j.consoleAppender

Log4j.Appender.stdout.Layout = Org.apache.log4j.patternlayout

Log4j.Appender.stdout.Layout.conversionPattern = [start]% d {yyyy / mm / dd / hh: mm: ss} [DATE]% N% P [priority]% N% x [NDC]% N% T [ Thread] N% C [category]% N% M [Message]% N% N

Log4j.Appender.file = org.apache.log4j.rollingfileappender

Log4j.Appender.file.file = oscache.log

Log4j.Appender.File.maxFileSize = 100KB

Log4j.Appender.file.maxbackupindex = 5

Log4j.Appender.File.Layout = Org.apache.log4j.patternlayout

LOG4J.APPENDER.FILE.LAYOUT.CONVERSIONPATTERN = [START]% D {YYYY / MM / DD / HH: MM: SS} [DATE]% N% P [Priority]% N% X [N% x [NDC]% N% T [ Thread] N% C [category]% N% M [Message]% n% nlog4j.logger.org.apache.commons = error

Log4j.logger.com.opensymphony.oscache.base = info

Commons-logging.properties file content

Org.apache.commons.logging.log = org.apache.commons.logging.Impl.log4jcategoryLog

2.Scache.properties file configuration wizard

Cache.memory

The value is True or False, which is default to cache in memory.

If set to false, the cache can only cache to the database or hard disk, what is the meaning of cache :)

Cache.capacity

Number of cache elements

Cache.Persistence.class

Persistence cache class, such open, you must set cache.path information

Cache.cluster

Set information for cluster.

Such as

Cache.cluster.multicast.ip is a broadcast IP address

Cache.cluster.properties is cluster properties

3. Basic usage of Soscache

Cache1.jsp contents are as follows

<% @ Page Import = "java.util. *"%>

<% @ Taglib Uri = "OSCache" prefix = "cache"%>

Date without caching: <% = new date ()%>

Refresh the cache every 30 seconds: <% = new Date ()%>

Date of manual refresh cache: <% = new date ()%>

manual refresh

Cache2.jsp executes the manual refresh page as follows

<% @ Taglib Uri = "OSCache" prefix = "cache"%>

Cache has been refreshed ...

Return

You can also define the effective range of cache by the following statement, if you do not define scope, Scope defaults to Applcation

...

4. Cache filter Cachefilter

You can define a cache filter in Web.xml to define a cache for a particular resource.

cachefilter

com.opensymphony.oscache.web.filter.cachefilter

Time

60

scope

session

cachefilter

*. jsp

The above definition will cache all .jsp pages, cache refresh time is 60 seconds, cache scope is session

Note that Cachefilter only captures a page request of the HTTP header 200, that is, only to caches the errorless request,

And don't work for other requests (such as 500, 404, 400)

Programming

转载请注明原文地址:https://www.9cbs.com/read-106693.html

New Post(0)