`
winhyt
  • 浏览: 107307 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论

基本的JCS缓存配置

阅读更多
参考博客文章(谢谢下面这些文章的作者):
1、http://blog.sina.com.cn/s/blog_537c07f60100094l.html
2、http://blog.chinaunix.net/u/15511/showart_101263.html
3、jcs.pdf英文文档

今天研究了下 jcs ,从网上查了一些资料(首先谢谢各位提供帮助的大虾啦),为了方便以后查找,现整理出来,有不全或者不正确的地方,望大家 指正。
基本的JCS配置:
1、默认的内存缓存:
该cache.ccf配置文件是放置到web-inf/classes/目录下的! 同时如果配置文件内没有指定特定的缓冲区的属性,所有缓冲区都会根据默认属性来构建。
Jcs.default=
Jcs.default.cacheattributes=
org.apache.jcs.engine.CompositeCacheAttributes
jcs.default.cacheattributes.MaxObjects=1000
jcs.default.cacheattributes.MemoryCacheName=
org.apache.jcs.engine.memory.lru.LRUMemoryCache

在上面的配置中,MaxObject 指定缓冲区的大小是存放1000个对象,1000个缓冲对象是指的每个缓冲区的大小为存放1000个对象,而不是指所有的缓冲区总容量。
其中 jcs.default=? 用来指定默认缓冲区对应的辅助缓冲区的名称!cacheattributes :设定使用的 cache 属性管理类别
MemoryCacheName 表示 内存缓冲区使用LRUMemoryCache对象。
2、如果需要加上缓存有效期限制,需要加上如下内容 接着上面的配置文件按(if you want to add memory shrinking then you can add these lines ):
jcs.defalut.cacheattritues.UserMemoryShrinker=true
jcs.default.cacheattributes.MaxMemoryIdleTimeSeconds=3600
jcs.default.cacheattributes.ShrinkerIntervalSeconds=60
jcs.default.MaxSpoolPerRun=500
jcs.default.elementattributes=org.apache.jcs.engine.ElementAttributes
jcs.default.elementattributes.IsEternal=false

上面的配置 中:
UserMemoryShrinker 属性设定是否使用冗余内存清除程序,true表示是
MaxMemoryIdleTimeSeconds 属性:表示 将UserMemoryShrinker 设为true时,jcs对缓冲的对象的最大滞留缓存中的时间,如果一个对象在缓冲区内停留的时间操作这个时间,就会被认为是“不新鲜的”而不清理掉或者存入磁盘 此次表示 3600秒则过期。
ShrinkIntervalSeconds 属性表示 对在缓存中的对象,多长时间检查一次,如果在检查的过程中发现有 驻留缓存大于 MaxMemoryIdleTimeSeconds 的,就将做过期处理。
Elementattributes 属性用来设定 element属性类别。

IsEternal 属性:用来设定 element 属性 是否会过期,(单词Eternal永久的意思)
= false  表示 不永久,就是会过期。
jcs.default.elementattributes.MaxLifeSeconds=2100 :设定 element 建立后能存活多久,IsEternal=false时有效
jcs.default.elementattributes.IdleTime=1800: 设定 element 可闲置的时间,IsEternal=false时有效
3.设置硬盘索引缓冲区(辅助缓冲区)
jcs.auxiliary.DC =
org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheFacory
jcs.auxiliary.DC.attributes=
org.apache.jcs.auxiliary.dis.indexed.IndexedDiskCacheAttributes
jcs.auxiliary.DC.attributes.DiskPath=g:/dev/jcs/raf

3、如果想将这个辅助硬盘索引缓冲区绑定到默认的缓冲区上,需要
修改默认缓冲区定义的第一条记录为
jcs.default =DC 即可,这样 所有未指定属性的缓冲区都会自己使用一个硬盘缓冲区,缓冲文件以缓冲区的名字来命名。存放到指定目录下。
4、如果想预定义一个具体的region缓冲区,比如叫做 testCache1,那么可以增加下面的配置:
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=true
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

5、完整的 配置文件如下(来自官方英文版pdf,加了点注释):
# DEFAULT CACHE REGION (默认缓冲区)jcs.default=DC,LTCP  -- 指明辅助缓冲区
jcs.default.cacheattributes=
org.apache.jcs.engine.CompositeCacheAttributes
jcs.default.cacheattributes.MaxObjects=1000
jcs.default.cacheattributes.MemoryCacheName=
org.apache.jcs.engine.memory.lru.LRUMemoryCache

# PRE-DEFINED CACHE REGIONS (预定义的region缓冲区(不是默认的,可以通过名称获取名称是 testCache1))jcs.region.testCache1=DC,LTCP
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=true
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 (硬盘索引辅助缓冲区和横向式的并行缓冲LTCP)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=g:/dev/jcs/raf
jcs.auxiliary.DC.attributes.maxKeySize=100000
jcs.auxiliary.LTCP=
org.apache.jcs.auxiliary.lateral.LateralCacheFactory
jcs.auxiliary.LTCP.attributes=
org.apache.jcs.auxiliary.lateral.LateralCacheAttributes
jcs.auxiliary.LTCP.attributes.TransmissionTypeName=TCP
jcs.auxiliary.LTCP.attributes.TcpServers=localhost:1111
jcs.auxiliary.LTCP.attributes.TcpListenerPort=1110

分享到:
评论
1 楼 mr.shang 2010-11-05  
很详细。感谢

相关推荐

Global site tag (gtag.js) - Google Analytics