OSCache

OSCache is a widely used, high performance J2EE caching framework.

Overview
OSCache is a caching solution that includes a JSP tag library and set of classes to perform fine grained dynamic caching of JSP content, servlet responses or arbitrary objects. It provides both in memory and persistent on disk caches, and can allow your site to have graceful error tolerance (eg if an error occurs like your db goes down, you can serve the cached content so people can still surf the site almost without knowing).

Requirement
OSCache can be used directly to provide caching for any Java application. Using the OSCache tag library requires Servlet 2.3 and JSP 1.2 support (included in J2EE 1.3) to run properly. There is no dependency on a servlet container if the OSCache API is used directly.
OSCache requires at least Java 1.4 for the installation.

Installation Guide


This installation guide shows you how to configure OSCache 2.3 for use inside your JSP pages. It assumes you have downloaded the latest version, which requires at least Java 1.4 and a Servlet 2.3 container (part of J2EE 1.3). Read the Requirements for more details.

If you intend to use OSCache via the API rather than via the taglibs, these instructions do not apply. Just make sure oscache.jar and commons-logging.jar are somewhere on your application's classpath.

Extraction Steps
  1. Extract the downloaded file to a directory of your choosing.
  2. Put the oscache.jar file in the /WEB-INF/lib directory
  3. Make sure commons-logging.jar is on your classpath (normally this also means putting it in /WEB-INF/lib).
  4. Put the /etc/oscache.properties file in the /WEB-INF/classes directory and edit the properties contained within it (for example if you want disk caching, configure the persistence listener and edit the cache.path property to point to where you want the cache files stored on disk). See the Configuration Guide for further details on what options are available.
  5. Your directory structure should now look something like this:

    $WEB_APPLICATION\WEB-INF\lib\oscache.jar
    $WEB_APPLICATION\WEB-INF\classes\oscache.properties
    $WEB_APPLICATION\WEB-INF\classes\oscache.tld


    将下列代码加入web.xml文件中
    <taglib>
    <taglib-uri>oscache</taglib-uri>
    <taglib-location>/WEB-INF/classes/oscache.tld</taglib-location>
    </taglib>

    为了便于调试日志输出,须加入commons-logging.jar和log4j-1.2.8.jar到当前类库路径中

    在src目录加入下面两个日志输出配置文件:
    log4j.properties 文件内容为:
    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[NDC]%n%t[THREAD] n%c[CATEGORY]%n%m[MESSAGE]%n%n


    log4j.logger.org.apache.commons=ERROR
    log4j.logger.com.opensymphony.oscache.base=INFO


    commons-logging.properties 文件内容为

    org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JCategoryLog

    2.oscache.properties 文件配置向导

    cache.memory
    值为true 或 false ,默认为在内存中作缓存,
    如设置为false,那cache只能缓存到数据库或硬盘中,那cache还有什么意义:)

    cache.capacity
    缓存元素个数

    cache.persistence.class
    持久化缓存类,如此类打开,则必须设置cache.path信息

    cache.cluster 相关
    为集群设置信息。

    cache.cluster.multicast.ip为广播IP地址
    cache.cluster.properties为集群属性


    3.OSCache的基本用法

    cache1.jsp 内容如下

    <%@ page import="java.util.*" %>
    <%@ taglib uri="oscache" prefix="cache" %>




    没有缓存的日期: <%= new Date() %>



    <cache:cache time="30">
    每30秒刷新缓存一次的日期: <%= new Date() %>
    </cache:cache>
     


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值