JCS---一个实现
来源:互联网 发布:重庆淘宝设计运营培训 编辑:程序博客网 时间:2024/05/16 12:29
Db4oObjManager:
package com.wl.cache;
import net.sourceforge.wurfl.core.resource.ModelDevice;
import org.apache.jcs.JCS;
import com.zx.dao.WurflDao;
public class Db4oObjManager
{
private static Db4oObjManager instance;
private static int checkedOut = 0;
private static JCS bookCache;
private Db4oObjManager()
{
try
{
bookCache = JCS.getInstance("testCache1");
}
catch (Exception e)
{
System.out.println("bookCache is null");
// Handle cache region initialization failure
}
// Do other initialization that may be necessary, such as getting
// references to any data access classes we may need to populate
// value objects later
}
/**
* Singleton access point to the manager.
*/
public static Db4oObjManager getInstance()
{
synchronized (Db4oObjManager.class)
{
if (instance == null)
{
instance = new Db4oObjManager();
}
}
synchronized (instance)
{
instance.checkedOut++;
}
return instance;
}
/**
* Retrieves a BookVObj. Default to look in the cache.
*/
public ModelDevice getBookVObj(String id)
{
return getBookVObj(id, true);
}
/**
* Retrieves a BookVObj. Second argument decides whether to look
* in the cache. Returns a new value object if one can't be
* loaded from the database. Database cache synchronization is
* handled by removing cache elements upon modification.
*/
public ModelDevice getBookVObj(String id, boolean fromCache)
{
ModelDevice vObj = null;
// First, if requested, attempt to load from cache
if (fromCache)
{
// System.out.println(bookCache);
vObj = (ModelDevice) bookCache.get("testCache1" + id);
}
// Either fromCache was false or the object was not found, so
// call loadBookVObj to create it
if (vObj == null)
{
vObj = loadBookVObj(id);
}
// else
// {
// System.out.println("bookCache get device from cache "+ id);
// }
return vObj;
}
/**
* Creates a BookVObj based on the id of the BOOK table. Data
* access could be direct JDBC, some or mapping tool, or an EJB.
*/
public ModelDevice loadBookVObj(String id)
{
// ModelDevice vObj = new BookVObj();
ModelDevice vObj = null;
// vObj.bookID = id;
try
{
boolean found = false;
// load the data and set the rest of the fields
// set found to true if it was found
vObj=WurflDao.queryById(id);
if(vObj!=null)
{
found = true;
}
else
{
System.out.println("cant find modeldevice from db");
}
// cache the value object if found
if (found)
{
// could use the defaults like this
// or specify special characteristics
// put to cache
bookCache.put("testCache1" + id, vObj);
System.out.println("bookCache put "+ id);
}
}
catch (Exception e)
{
// Handle failure putting object to cache
}
return vObj;
}
/**
* Stores BookVObj's in database. Clears old items and caches
* new.
*/
public void storeBookVObj(ModelDevice vObj)
{
try
{
// since any cached data is no longer valid, we should
// remove the item from the cache if it an update.
if (vObj.getID() != "")
{
bookCache.remove("testCache1" + vObj.getID());
}
// put the new object in the cache
bookCache.put("testCache1" + vObj.getID(), vObj);
}
catch (Exception e)
{
// Handle failure removing object or putting object to cache.
}
}
}
cache.ccf :
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# #############################################################
# ################# DEFAULT CACHE REGION #####################
# sets the default aux value for any non configured caches
# #############################################################
# ################# CACHE REGIONS AVAILABLE ###################
# Regions preconfirgured for caching
jcs.region.testCache1=DC
jcs.region.testCache1.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.region.testCache1.cacheattributes.MaxObjects=10000
jcs.region.testCache1.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
jcs.region.testCache1.cacheattributes.UseMemoryShrinker=true
jcs.region.testCache1.cacheattributes.ShrinkerIntervalSeconds=30
jcs.region.testCache1.cacheattributes.MaxMemoryIdleTimeSeconds=300
jcs.region.testCache1.cacheattributes.MaxSpoolPerRun=100
jcs.region.testCache1.elementattributes=org.apache.jcs.engine.ElementAttributes
jcs.region.testCache1.elementattributes.IsEternal=false
jcs.region.testCache1.elementattributes.IsLateral=true
- JCS---一个实现
- JCS
- JCS实现分布式缓存共享
- 用JCS实现javaEE项目缓存
- JCS实现项目缓存总结之二
- JCS 使用
- JCS配置
- jcs配置
- JCS 缓存
- JCS学习
- JCS下载
- 使用JCS在Web门户应用中实现对象缓存(1)
- 使用JCS在Web门户应用中实现对象缓存(2)
- 使用JCS在Web门户应用中实现对象缓存(3)
- 使用JCS在Web门户应用中实现对象缓存(1)
- 使用JCS在Web门户应用中实现对象缓存(2)
- 使用JCS在Web门户应用中实现对象缓存(3)
- Hibernate Iterator JCS分析
- 规则化和模型选择(Regularization and model selection)
- 如何使用javascript的PureMVC框架 - Mediator/View层
- C语言 gets()和scanf()函数的区别
- 遍历对象的所有属性和属性值
- grep不查找隐藏文件夹的方法
- JCS---一个实现
- 普通Java类获取Spring的ApplicationContext
- java inputstream 读取数据
- 对不起,你的服务器没有安装动易组件(PE_Article6.dll),所以不能使用动易系统。"---解决方
- 看nutch学习hadoop的编程
- zoj一道题:fire net 给的测试用例都通过就是不能ac求助测试
- 键盘事件解析
- CentOS 更改MySQL数据库目录位置
- 汇编语言编写十进制数到二进制数的进制转换并显示的子程序