hibernate二级缓存ehcache.xml文件配置的几条心得

1 篇文章 0 订阅
1 篇文章 0 订阅

网上有不少介绍hibernate二级缓存ehcache的配置,本文也不想重复。只是,对初学者,提出几点另外的建议。

 

1.jar

所需的jar包至少有hibernate(版本)包、ehcache-core-2.5.2.jar包、ehcache-web-2.0.4.jar包。或以上版本。

提供一个下载链接:

Ehcache 对象、数据缓存:http://ehcache.org/downloads/destination?name=ehcache-core-2.5.2-distribution.tar.gz&bucket=tcdistributions&file=ehcache-core-2.5.2-distribution.tar.gz

Web页面缓存:http://ehcache.org/downloads/destination?name=ehcache-web-2.0.4-distribution.tar.gz&bucket=tcdistributions&file=ehcache-web-2.0.4-distribution.tar.gz

 

 

2.ehcache.xml文件如何创建或生成。

 

新建一个xml文件,用Basic Templetes 。有网友说hibernate.jar包里面也有,你去找吧。反正我没找到。Ehcache.xml属性配置,网上很多,这个只要拷一下就行。

 

3.ehcache.xml文件配置注意事项:

(1)仅有<defaultCache/>属性是可以的。在添加<cache name=”” />后,<defaultCache/>还是需要的。不然会报错:

 

Caused by: net.sf.ehcache.CacheException: Caches cannot be added by name when default cache config is not specified in the config. Please add a default cache config in the configuration.

 

 

(2)从映射文件.hbm.xml中的配置:

 

  <cache usage="read-write" region="model 对象"/>

 

可知,Ehcache缓存的最小单位是对象。而如果仅设置对象中某些属性为缓存。比如一个User对象,它包含idnamepassword三个字段,如果我仅想将name存为缓存,Ehcache好像无能为力。


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值