- 浏览: 21091 次
文章分类
最新评论
1.从http://www.opensymphony.com/oscache/download.html下载合适的OSCache版本.就现在最新版本oscache-2.4.1-full.zip.
解压缩下载的文件到指定目录
2. 将oscache-2.4.1.jar,commons-logging.jar复制到/WEB-INF/lib,将oscache.properties,oscache.tld拷到src目录下
3.在web.xml加上oscache.tld的配置:
<jsp-config>
<taglib>
<taglib-uri>oscacheTag</taglib-uri>
<taglib-location>/WEB-INF/class/oscache.tld</taglib-location>
</taglib>
</jsp-config>
4.如果需要对特定的页面进行过滤,使用oscache过滤器,在web.xml中添加
<filter>
<filter-name>CacheFilter</filter-name>
<filter-class>com.opensymphony.oscache.web.filter.CacheFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CacheFilter</filter-name>
<!--对所有jsp页面内容进行缓存-->
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
5.在jsp页面中引用oscache标签
<%@ taglib uri="oscacheTag" prefix="oscache" %>
也可以使用如下方式进行引用:
<%@ taglib uri="/WEB-INF/classes/oscache.tld" prefix="oscache" %>
在jsp页面中使用oscache标签:
<oscache:cache>
<%
out.print("这是在缓存内容");
%>
</oscache:cache>
6.oscache.properties的配置说明:
cache.memory
Valid values are true or false, with true being the default value. If you want to disable memory caching, just comment out or remove this line.
Note: disabling memory AND disk caching is possible but fairly stupid
cache.capacity
The maximum number of items that a cache will hold. By default the capacity is unlimited - the cache will never remove any items. Negative values will also be treated as meaning unlimited capacity.If a size is specified but not an algorithm, the cache algorithm used will be LRUCache.
cache.algorithm
The default cache algorithm to use. Note that in order to use an algorithm the cache size must also be specified. If the cache size is not specified, the cache algorithm will be Unlimited cache regardless of the value of this property. If you specify a size but not an algorithm, the cache algorithm used will be com.opensymphony.oscache.base.algorithm.LRUCache.
OSCache currently comes with three algorithms:
com.opensymphony.oscache.base.algorithm.LRUCache - Least Recently Used. This is the default when a cache.capacity is set.
com.opensymphony.oscache.base.algorithm.FIFOCache - First In First Out.
com.opensymphony.oscache.base.algorithm.UnlimitedCache - Content that is added to the cache will never be discarded. This is the default when no value is set for the cache.capacity property.
cache.blocking
When a request is made for a stale cache entry, it is possible that another thread is already in the process of rebuilding that entry. This setting specifies how OSCache handles the subsequent 'non-building' threads. The default behaviour (cache.blocking=false) is to serve the old content to subsequent threads until the cache entry has been updated. This provides the best performance (at the cost of serving slightly stale data). When blocking is enabled, threads will instead block until the new cache entry is ready to be served. Once the new entry is put in the cache the blocked threads will be restarted and given the new entry.
Note that even if blocking is disabled, when there is no stale data available to be served threads will block until the data is added to the cache by the thread that is responsible for building the data.
cache.unlimited.disk
Use unlimited disk cache or not. The default value is false, which means the disk cache will be limited in size to the value specified by cache.capacity.
cache.persistence.class
Specifies the class to use for persisting cache entries. This class must implement the PersistenceListener interface. OSCache comes with an implementation that provides filesystem based persistence. Set this property to com.opensymphony.oscache.plugins.diskpersistence.HashDiskPersistenceListener to enable this implementation. By specifying your own class here you should be able to persist cache data using say JDBC or LDAP. NOTE: This class hashes the toString() of the object being cached to produce the file name of the entry. If you prefer readable file names, the parent DiskPersistenceListener can still be used but it will have issues with illegal filesystem characters or long names.
Note
The HashDiskPersistenceListener and DiskPersistenceListener classes require cache.path to be set in order to know where to persist the files to disk.
cache.path
This specifies the directory on disk where the caches will be stored. The directory will be created if it doesn't already exist, but remember that OSCache must have permission to write to this location. Avoid sharing the same cache path between different caches, because OSCache has not been designed to handle this.
Note
For Windows machines, the backslash character '\' needs to be escaped. ie in Windows:
cache.path=c:\\myapp\\cache
or *ix:
cache.path=/opt/myapp/cache
cache.persistence.overflow.only
Indicates whether the persistence should only happen once the memory cache capacity has been reached. The default value is false for backwards compatibility but the recommended value is true when the memory cache is enabled. This property drastically changes the behavior of the cache in that the persisted cache will now be different then what is in memory.
cache.event.listeners
This takes a comma-delimited list of fully-qualified class names. Each class in the list must implement one (or more) of the following interfaces:
CacheEntryEventListener - Receives cache add/update/flush and remove events.
CacheMapAccessEventListener - Receives cache access events. This allows you to keep statistical information to track how effectively the cache is working.
No listeners are configured by default, however some ship with OSCache that you may wish to enable:
com.opensymphony.oscache.plugins.clustersupport.BroadcastingCacheEventListener - provides clustering support for OSCache. Enabling this will cause cache flush events to be broadcast to other instances of OSCache running on your LAN. See Clustering OSCache for further information about this event listener.
com.opensymphony.oscache.extra.CacheEntryEventListenerImpl - a simple listener implementation that maintains a running count of all of the entry events that occur during a cache's lifetime.
com.opensymphony.oscache.extra.CacheMapAccessEventListenerImpl - a simple listener implementation that keeps count of all the cache map events (cache hits and misses, and stale hits) that occur on a cache instance.
It is also of course quite straightforward to write your own event listener. See the JavaDoc API for further details and Statistics for an example.
cache.key
This is the key that will be used by the ServletCacheAdministrator (and hence the custom tags) to store the cache object in the application and session scope. The default value when this property is not specified is "__oscache_cache". If you want to access this default value in your code, it is available as com.opensymphony.oscache.web.ServletCacheAdministrator.DEFAULT_CACHE_KEY.
cache.use.host.domain.in.key
If your server is configured with multiple hosts, you may wish to add host name information to automatically generated cache keys. If so, set this property to true. The default value is false.
Additional Properties
In additon to the above basic options, any other properties that are specified in this file will still be loaded and can be made available to your event handlers. For example, the JavaGroupsBroadcastingListener supports the following additional properties:
cache.cluster.multicast.ip
The multicast IP to use for this cache cluster. Defaults to 231.12.21.132.
cache.cluster.properties
Specifies additional configuration options for the clustering. The default setting is
UDP(mcast_addr=231.12.21.132;mcast_port=45566;ip_ttl=32;\
mcast_send_buf_size=150000;mcast_recv_buf_size=80000):\
PING(timeout=2000;num_initial_members=3):\
MERGE2(min_interval=5000;max_interval=10000):\
FD_SOCK:VERIFY_SUSPECT(timeout=1500):\
pbcast.NAKACK(gc_lag=50;retransmit_timeout=300,600,1200,2400,4800;max_xmit_size=8192):\
UNICAST(timeout=300,600,1200,2400):\
pbcast.STABLE(desired_avg_gossip=20000):\
FRAG(frag_size=8096;down_thread=false;up_thread=false):\
pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;shun=false;print_local_addr=true)
相关推荐
**Oscache使用教程** Oscache是一款开源的Java缓存解决方案,主要用于提高Web应用程序的性能,通过在内存中存储经常访问的数据,避免了频繁的数据库查询,从而减少了系统响应时间。本文将深入探讨Oscache的基本原理...
OSCache是OpenSymphony这个开源项目众多Projects中的一个。他是一个高效的J2EE缓存框架,能够很好的解决动态网站速度的问题。
一个典型的osCache使用实例可能是这样的: ```java import net.sf.oscache.CacheManager; public class OSCacheExample { public static void main(String[] args) { CacheManager cacheManager = CacheManager....
在本文中,我们将深入探讨 osCache 的核心概念、使用场景以及如何在项目中有效地利用它。** ### 一、缓存的重要性 在Web应用中,缓存是一种常见的优化手段,它能够显著提升系统的响应速度,减轻数据库的压力。当...
**三、OSCache使用指南** 1. **下载与安装** - 从OpenSymphony官方网站下载OSCache,解压缩至指定目录。 - 创建新的Web应用。 - 将`oscache.jar`放入`WEB-INF/lib`目录。 - 将`oscache.properties`和`oscache....
四、osCache使用示例 1. 添加依赖:在你的项目中引入osCache的JAR文件或通过Maven/Gradle等构建工具添加依赖。 2. 初始化缓存:在应用程序启动时初始化osCache,这通常在Servlet容器的初始化回调方法中完成。 ```...
osCache 是一款强大的缓存解决方案,尤其在Java开发中被广泛使用。它不仅提供了类似于Map的数据结构操作,还具备内置的集群支持,使得数据缓存可以在分布式环境中高效地进行。这个"oscache-2.1.1-full.zip"压缩包...
OSCache 是一个广泛使用的缓存解决方案,它支持多种技术,如 Hibernate、JSP 和页面缓存。本篇文章将深入探讨 OSCache 的配置和使用方法。 首先,安装 OSCache 包括以下几个步骤: 1. 从官方网站...
OSCache是一个高性能、易于使用的缓存组件,主要用于Web应用程序中数据的缓存管理。它可以极大地提高Web应用的性能,通过减少对数据库或其他后端系统的访问频率来降低服务器负载。OSCache支持多种缓存策略,并且可以...
在 JSP 页面中,可以通过以下方式使用 OSCache 标签库进行缓存配置: ```jsp <%@ taglib uri="http://www.opensymphony.com/oscache" prefix="oscache" %> <oscache:cache page="true" timeToLive="600"> <!-- ...
### 三、OSCache使用指南 #### 1. 安装与配置 - **下载**:从OpenSymphony官网下载OSCache的最新版本。 - **解压**:将下载的文件解压到指定目录。 - **新建Web应用**:创建一个新的Web项目。 - **集成OSCache**:...
以下是一个简单的OSCache使用示例: ```java import net.sf.oscache.CacheManager; import net.sf.oscache.Cache; // 初始化缓存管理器 CacheManager.init("path/to/oscache.xml"); // 获取或创建名为"myCache"的...
osCache使用了基于JGroups的组通信协议来实现集群间的通信,JGroups提供了可靠的组成员发现和消息传递机制。 三、数据同步机制 osCache的数据同步策略主要基于两种机制:推送(Push)和拉取(Pull)。 1. 推送...
- **内存管理**:Oscache使用了一种基于LRU(Least Recently Used)策略的内存管理机制,自动移除最少最近使用的缓存项以保持内存使用在设定的阈值内。 - **缓存预热**:支持预加载缓存,使得应用启动后即可快速...
本示例将通过一个天气预报Web服务的场景,详细介绍OsCache的使用方法。 首先,我们需要了解OsCache的基本概念。OsCache的核心是基于哈希表的数据结构,它可以在内存中存储对象,支持自动过期策略,可以设置缓存项的...
本文档详细介绍了OSCache的配置与使用,旨在为开发者提供一份全面的参考指南。OSCache是由OpenSymphony开发的开源缓存框架,它为J2EE应用程序提供了高效、灵活的缓存解决方案。 文档介绍 文档目的: 本文档的主要...
**Oscache使用示例** 1. **引入依赖**:在项目中添加Oscache的jar包,或者通过Maven或Gradle等构建工具进行依赖管理。 2. **配置初始化**:在`web.xml`或通过代码创建`CacheManager`,加载`oscache.properties`配置...
标题与描述概述的知识点主要集中在oscache的使用及其在Java环境下的配置与实施。oscache是一种缓存机制,主要用于提高Web应用的响应速度和优化系统性能。以下是对这些知识点的详细解析: ### oscache简介 oscache...