缓存 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>

 

 

 

猜你喜欢

转载自mrrigth.iteye.com/blog/1847288