概述
使用JCS需要完成以下骤:
1. 了解核心概念。
2. 下载JCS
3. 获得JCS依赖
4. 配置JCS
5. 开始编程应用
入门指南的目的是尽可能快帮助你搭建和运行JCS,JCS各种各样的特性的深入文档在用户指南中提供。
第一步 了解核心的概念
为了使用JCS,你必须知道一些核心的概念,最重要是你需要知道”elements”,”regions”,和“auxiliaries”这间有什么不同
JCS是一个对象缓存,你能放置一些对象或是”elements”并通过key来访问它们,很象一个hashtable。
你可以想象JCS是一个能过Name来获取的hashtables的集合。其中每一个hashtables都被称做“region”,每一个region都能被独立于其他regions配置。例如,我可以有一个称做城市的region,我缓存了一些定期被改变的城市对象。我也可以定义一个region被叫做产品,我缓存一些定期改变的产品数据。我将可以配置易变的产品的region elements 过期时间要快于city的region
Auxiliaries是region能用的插件选项。核心的Auxiliaries是Indexed Disk Cache(磁盘索引缓存)、TCP Lateral Cache(TCP横向缓存)、Remote Cache Server(远程缓存服务器)。例如,磁盘缓存允许当你的内存达到阈值后把缓存对象交换到硬上。
第二步下载jcs
第三步,获得JCS依赖
第四步,配置JCS
JCS配置在一个叫"cache.ccf"的配置文件中,有替代品使用此文件,但他们超越了入门指南的范围。
缓存配置分为三部分:默认配置,regions配置和auxiliaries配置。你可以把auxiliaries想象为log4j的log4j appenders,regions是log4j categories。每一个region都能指定auxiliaries。如果一个region不在Cache.ccf进行配置,则它将会使用默认的配置。以JCS和log4j 不同的是JCS中预先定义的region不能使default region内auxiliaries。
下面的cache.ccf文件定义了叫做”testCache1”的region,这个region使用了Indexed Disk Cache的axiliaries,它在这里被默认叫做DC。LRU内存缓存被选择用来管理内存
# DEFAULT CACHE REGION jcs.default=DC jcs.default.cacheattributes= org.apache.jcs.engine.CompositeCacheAttributes jcs.default.cacheattributes.MaxObjects=1000 jcs.default.cacheattributes.MemoryCacheName= org.apache.jcs.engine.memory.lru.LRUMemoryCache jcs.default.cacheattributes.UseMemoryShrinker=false jcs.default.cacheattributes.MaxMemoryIdleTimeSeconds=3600 jcs.default.cacheattributes.ShrinkerIntervalSeconds=60 jcs.default.elementattributes=org.apache.jcs.engine.ElementAttributes jcs.default.elementattributes.IsEternal=false jcs.default.elementattributes.MaxLifeSeconds=21600 jcs.default.elementattributes.IdleTime=1800 jcs.default.elementattributes.IsSpool=true jcs.default.elementattributes.IsRemote=true jcs.default.elementattributes.IsLateral=true # PRE-DEFINED CACHE REGIONS jcs.region.testCache1=DC jcs.region.testCache1.cacheattributes= org.apache.jcs.engine.CompositeCacheAttributes jcs.region.testCache1.cacheattributes.MaxObjects=1000 jcs.region.testCache1.cacheattributes.MemoryCacheName= org.apache.jcs.engine.memory.lru.LRUMemoryCache jcs.region.testCache1.cacheattributes.UseMemoryShrinker=false jcs.region.testCache1.cacheattributes.MaxMemoryIdleTimeSeconds=3600 jcs.region.testCache1.cacheattributes.ShrinkerIntervalSeconds=60 jcs.region.testCache1.cacheattributes.MaxSpoolPerRun=500 jcs.region.testCache1.elementattributes=org.apache.jcs.engine.ElementAttributes jcs.region.testCache1.elementattributes.IsEternal=false # AVAILABLE AUXILIARY CACHES jcs.auxiliary.DC= org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheFactory jcs.auxiliary.DC.attributes= org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheAttributes jcs.auxiliary.DC.attributes.DiskPath=${user.dir}/jcs_swap jcs.auxiliary.DC.attributes.MaxPurgatorySize=10000000 jcs.auxiliary.DC.attributes.MaxKeySize=1000000 jcs.auxiliary.DC.attributes.MaxRecycleBinSize=5000 jcs.auxiliary.DC.attributes.OptimizeAtRemoveCount=300000 jcs.auxiliary.DC.attributes.ShutdownSpoolTimeLimit=60
第五步:JCS编码
JCS提供了一个方便的类,org.apache.jcs.JCS这个类将可以满足你的需要。它可以仅仅通用region Name来获取一个region。如果你想要使用JCS的City 集合,你可以如以下使用:
import org.apache.jcs.JCS; import org.apache.jcs.access.exception.CacheException; . . . private static final String cacheRegionName = "city"; private JCS cache = null; . . . // in your constructor you might do this try { setCache( JCS.getInstance( this.getCacheRegionName() ) ); } catch ( CacheException e ) { log.error( "Problem initializing cache for region name [" + this.getCacheRegionName() + "].", e ); } . . . // to get a city out of the cache by id you might do this: String key = "cityId:" + String.valueOf( id ); City city = (City) cache.get( key ); . . . // to put a city object in the cache, you could do this: try { // if it isn't null, insert it if ( city != null ) { cache.put( key, city ); } } catch ( CacheException e ) { log.error( "Problem putting " + city + " in the cache, for key " + key, e ); }
相关推荐
JCS缓存入门及简介
JCS缓存所需jar
JCS是一个用java编写的分布式缓存系统。它被设计用来加速应用程序,通过提供一个手段来管理多种变化种类的缓存数据。像其它缓存系统一样,JCS对高读(high read)、低放(low put)的应用程序非常有用。 JCS超越了...
JCS是一个用java编写的分布式缓存系统。它被设计用来加速应用程序,通过提供一个手段来管理多种变化种类的缓存数据。像其它缓存系统一样,JCS对高读(high read)、低放(low put)的应用程序非常有用。 JCS超越了...
jcs缓存所需要的包。导入这两个包即可使用jcs缓存策略
jcs-1.3资源包下载,没什么可描述的, 自己下载看吧
jcs 所需的三个jar包 还没来得及测试
简单的jcs实例,需要一些jar包,对于占用大量内存的代码可以考虑用jcs.
JCS在一般用在,查询数据库比较频繁,每次查询的结果都差不多,这样讲数据进行缓冲,可以 减轻数据库负担: 下面举个例子: 在一个点击量比较频繁的页面,调用一个数据列表,每个用户进去在某一时间段数据都一样,...
昆仑海岸 JCS大量程系列超声波物位变送器使用说明书PDF,昆仑海岸 JCS大量程系列超声波物位变送器使用说明书
佳灵JCS高压变频器彩色样本PDF版pdf,佳灵JCS高压变频器彩色样本PDF版
commons-jcs针对web开发缓存处理
资源分类:Python库 所属语言:Python 资源全名:jcson-0.1.1-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
JCS-018立时加工中心主轴箱及(sw+说明书+cad).rar
今天看到csdn 上的一个哥们,将这个资源的资源分设为10,从另外的地方找了一份,特上传与大家分享。
What jars are required by JCS? As of verison 1.2.7.0, the core of JCS (the LRU memory cache, the indexed disk cache, the TCP lateral, and the RMI remote server) requires only two other jars. ...
JCS-018立时加工中心主轴箱及(sw+说明书+cad)cad图纸毕业生设计书.zip
(Java Caching System)基于数据库的WEB应用程序加上缓存,以提高性能
NULL 博文链接:https://phl.iteye.com/blog/2240901
昆仑海岸 JCS-10系列超声波物位变送器使用说明书PDF,昆仑海岸 JCS-10系列超声波物位变送器使用说明书