缓存 ehcache

一级缓存 session

二级缓存 sessionpool 可以跨session存在

三级缓存 session 相同查询语句 

 

适用于二级缓存的情况

经常被问

不经常改动

数量有限

ehcache 需要导入两个jar ehcache.jar and commons-logging.jar

  1.  引入ehcache.xml
  2. 在ehcache里修改defaultCache  (注eternal是否永远存在,idleSeconds是未使用时间,LiveSeconds 使用时间.单位秒)

 

查询缓存依赖于二级缓存

配置hibernate.xml <property name="cache.use_query_cache">true</property>

执行list()前面要加上setCacheable(true) //使用查询缓存

 

缓存算法:设置 memoryStoreEvictionPolicy="LRU"(ehcache)

LRU 以时间排序 访问时间最晚的pass

LFU 以使用次数  调用最少的pass

FIFO 先进先出

 

 

spring3+hibernate4配置中遇到的问题

We couldn't load configuration data from the server at 'localhost:9510'; retrying. (Error: Connection refused: connect.)

Terracotta caches are defined but no <terracottaConfig> element was used to specify the Terracotta configuration.

 

以上两个错误来源
因为我是直接从ehcache包里边的那个例子拷贝过来的ehcache.xml
默认带有集群的配置所以使用时需要注释两个地方  
  <terracottaConfig url="localhost:9510"/> //一个是这里指定集群服务器 注释掉

    <defaultCache
            maxEntriesLocalHeap="0"
            eternal="false"
            timeToIdleSeconds="600"
            timeToLiveSeconds="1200">
        <terracotta/>                      //一个是这里定义使用集群 注释掉
    </defaultCache>

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值