Ehcache配置及缓存算法

hiberate的缓存有3种 1.一级缓存session 2.二级缓存 3.查询缓存
首先将ehcache.xml放入到项目根目录中
spring_cfg.xml中配置
<!-- 开启二级缓存 -->
<prop key="hibernate.cache.use_second_level_cache">net.sf.ehcache.hibernate.EhCacheProvider}</prop>
<prop key="hibernate.cache.provider_class">true</prop>
<!-- 开启二级缓存的查询缓存 -->
<prop key="hibernate.cache.use_query_cache">true</prop>
<!-- Ehcache的配置文件路径-->
<prop key="hibernate.cache.provider_configuration_file_resource_path">ehcache.xml</prop>
在实体bean中用注解配置
@Entity
@Table(name = "Bsp_areaattachment_table")
//配置缓存的读写,一般使用两种READ_ONLY和READ_WRITE
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class BspProjectAreaAttachment implements Serializable {
}
在Session中设置
session.setCacheable(true)则查询的时候使用缓存
缓存算法
1:LRU LFU FIFO
LRU:按最近很少使用的对象来算,则拿走该对象,这个是有一个时间标识的
LFU:按命中率的高低来算,也就是按最少使用的对象来算,则移走
FIFO:数组,最后将0推走

猜你喜欢

转载自zhouyunchao.iteye.com/blog/2166103