Oscache is an open JSP custom tag application designed by Opensymphony to provide fast memory buffering within existing JSP pages.
Oscache is a widely used, High-performance Java Java Cache framework that Oscache can be used for any common caching solution for any java-based application. Oscache has the following features: Caching any object, you can cache some JSP pages or HTTP requests without restriction, any Java object can be cached. Having a comprehensive Api--oscache API gives you a comprehensive program to control all Oscache features. Persistent caching-caching can be written to the hard disk at will, allowing expensive creation (expensive-to-create) data to remain cached and even restart the application. Support cluster--the cluster cache data can be configured individually and without the need to modify the code. Expiration of cached records-you can have maximum control over the expiration of cached objects, including pluggable refresh policies (if the default performance is not required).
Oscache is the form of storing the cache as a map, by default the cached key consists of the requested URL and the query string. Acquisition and use of Scache get Oscache related files
Get the appropriate version of Oscache from http://www.opensymphony.com/oscache/, where we have downloaded Oscache-2.4-full.zip configuration in the project Oscache
Unzip the Oscache-2.4-full.zip, put the oscache-2.4.jar and reconciliation in the root directory of the Lib folder under the Commons-logging.jar into the project.
Copy the oscache.properties files under the directory etc folder to the SRC directory of the project. Page-local caching using Oscache is introduced in pages that need to be cached
<%@ taglib uri= "/web-inf/lib/oscache-2.4.jar" prefix= "Cache"%>
Use <cache:cache> tags in local areas where caching is required to obtain the required parameter information from the Param
<cache:cache>
User=${param.user}
</cache:cache>
Set cache to save in session:
<cache:cache scope= "Session" >
user=${param.user}
</cache:cache>
By default, the cached key consists of the requested URL and query string, and if you need to set the cached key, you can set it as follows:
<cache:cache key= "User" >
user=${param.user}
</cache:cache>
In this way, the cached key is user, and any value given to the user variable in the URL will only get a cache (that is, the value of user as key). Set the cache time for the local cache, in seconds:
<cache:cache key= "user" time= ">
user=${param.user}
</cache:cache>
This sets the cache refresh with a local cache time of 23 seconds: Set Cache refresh Parameters:
<cache:cache key= "user" time= "refresh=" ${param.refresh} ">
user=${param.user}
</cache:cache >
In this way, the cache is automatically cleared when the URL passes over the argument to be true. Clear all caches in application range:
<cache:flush scope= "Application"/>
Clears all caches for the specified key in session:
<cache:flush scope= "Session" key= "user"/>
Clears all caches for the specified group name within the session:
<cache:flush scope= "Session" group= "UserGroup"/>
Use the Oscache page global cache:
Add the associated filter of Oscache in the web.xml and make the required settings:
<filter>
<filter-name>CacheFilter</filter-name>
<filter-class> com.opensymphony.oscache.web.filter.cachefilter</filter-class>
<init-param>
<param-name >time</param-name>
<param-value>7200</param-value>
</init-param>
< init-param>
<param-name>scope</param-name>
<param-value>application</ param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name >CacheFilter</filter-name>
<url-pattern>/cache/*</url-pattern>
</ Filter-mapping>
Common configurations in Oscache.properties:
#缓存到硬盘上
cache.memory=false
#缓存到硬盘上时需要设置, set the persistence class Diskpersistencelistener and persist to the hard drive
Cache.persistence.class=com.opensymphony.oscache.plugins.diskpersistence.diskpersistencelistener
# When cached on the hard drive, it needs to be set, cached to the path on the hard drive
cache.path=d:\\myapp\\cache
#设置缓存数量
cache.capacity=1000
# Set cache to cache on drive when memory overflows
cache.persistence.overflow.only=true
Reprint Source Address: http://www.itzhai.com/ Oscache-caching-framework-introduced-local-cache-and-global-cache-use-and-basic-configuration-items.html