2007-12-10
JCS 应用
关键字: JCSJCS在一般用在,查询数据库比较频繁,每次查询的结果都差不多,这样讲数据进行缓冲,可以 减轻数据库负担:
下面举个例子:
在一个点击量比较频繁的页面,调用一个数据列表,每个用户进去在某一时间段数据都一样,这时将考虑将数据进行缓冲。
1、配置 JCS cache.ccf 文件,将该文件直接放到src根目录下即可:
java 代码
- /**缓冲区名称**/
- jcs.region.chatCache=DC
- /****/
- jcs.region.chatCache.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
- /**缓冲区的大小为存放1000个对象**/
- jcs.region.chatCache.cacheattributes.MaxObjects=10000
- /**内存缓冲器使用LRUMemoryCache对象**/
- jcs.region.chatCache.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
- /****/
- jcs.region.chatCache.cacheattributes.UseMemoryShrinker=true
- /**指明对象超过2000秒则过期**/
- jcs.region.chatCache.cacheattributes.MaxMemoryIdleTimeSeconds=2000
- /**每隔60秒检查一次**/
- jcs.region.chatCache.cacheattributes.ShrinkerIntervalSeconds=60
- /****/
- jcs.region.chatCache.cacheattributes.MaxSpoolPerRun=500
- /****/
- jcs.region.chatCache.elementattributes=org.apache.jcs.engine.ElementAttributes
- /****/
- jcs.region.chatCache.elementattributes.IsEternal=false
- /****/
- jcs.region.chatCache.elementattributes.IsSpool=true
- /****/
- jcs.region.chatCache.elementattributes.IsRemote=false
- /****/
- jcs.region.chatCache.elementattributes.IsLateral=true
- /****/
- jcs.region.chatCache.elementattributes.MaxLifeSeconds=3600
2、程序中这样应用即可:
- JCS chatCache = JCS.getInstance("chatCache"); //获得JCS缓冲区对象
- String chatCacheKey = "chat_cache_"+roomID; // 构建key
- if(chatCache.get(chatCacheKey)!=null){
- roomintroList = (List)chatCache.get(chatCacheKey);
- }else{
- roomintroList = 数据库查询;
- chatCache.put(chatCacheKey, roomintroList);
- }
发表评论
- 浏览: 56186 次

- 详细资料
搜索本博客
最近加入圈子
最新评论
-
使用 xfire 开发 web ser ...
写的什么东西啊,中间还有html标签什么的.还不如不写.乱
-- by antonie1111 -
JCS 资料
引用引用引用引用引用引用引用引用引用引用
-- by LargeBean -
Hibernate-Criteria 模糊 ...
>>Expression.eq(String arg0, String arg1 ...
-- by NicholasBugs -
MyEclipse 6.0.1 注册码
有没有6.01 的professional edtion 上面那个不能调试。
-- by ztk5912 -
Java Message Service 概 ...
...
-- by vincent.xue






评论排行榜