OFBiz的Cache研究


任何一个cache对象的配置属性都可以在cache.properties设置。

{cache-name}.maxSize (内存大小)
{cache-name}.expireTime (失效时间)
{cache-name}.useSoftReference (true 或者 false).
该useSoftReference属性用于指定是否用于缓存条目。可以帮助保持大缓存,同时需要更多的内存垃圾回收器来清除这些项目占用过多内存。


例如
//    # 60 min
//    product.ecconfig.expireTime=3600000
//    product.ecconfig.useSoftReference=true
    public static UtilCache productCache = UtilCache.createUtilCache("product.ecconfig", true);


使用
if(UtilValidate.isNotEmpty(productCache.get(condition))){
        	long count =(Long) productCache.get(condition);
        	if(count>0){result="Y";}
        	else{result="N";}
        	return result;
        }
        
        try {
			long count = delegator.findCountByCondition("EcShopProduct", condition, null, null);
			productCache.put(condition, count);
			Debug.log(" productCategoryId="+productCategoryId+" productFeatureList="+productFeatureList+" count="+count, module);
			if(count>0){result="Y";}
		} catch (GenericEntityException e) {
			Debug.logError(e.getMessage(), module);
			return result;
		}




缓存工具
缓存管理
浏览缓存大小和命中/错失统计
清除全部缓存、单独的缓存甚至单独的缓存行
清除全部过期的缓存记录
管理缓存参数如大小限止、过期时间、软参考等
浏览每个缓存中的单独的元素

附cache的通用使用方法
http://www.amicontech.com/blog/caching-in-opentaps-ofbiz/

猜你喜欢

转载自jiasudu.iteye.com/blog/1997331