hibernate3开启查询缓存和二级缓存
<props> <prop key="hibernate.cache.use_query_cache">true</prop> <prop key="hibernate.cache.use_second_level_cache">true</prop> <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop> </props>
hibernate4开启查询缓存和二级缓存
<props> <prop key="hibernate.cache.use_query_cache">true</prop> <prop key="hibernate.cache.use_second_level_cache">true</prop> <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop> </props>
类的头部写法,如User.java
@Cacheable @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) pulbic class User{ }
ehcache配置文件ehcache.xml
<ehcache> <!-- Sets the path to the directory where cache .data files are created. If the path is a Java System Property it is replaced by its value in the running VM. The following properties are translated: user.home - User's home directory user.dir - User's current working directory java.io.tmpdir - Default temp file path --> <diskStore path="java.io.tmpdir"/> <!--Default Cache configuration. These will applied to caches programmatically created through the CacheManager. The following attributes are required for defaultCache: maxInMemory - Sets the maximum number of objects that will be created in memory eternal - Sets whether elements are eternal. If eternal, timeouts are ignored and the element is never expired. timeToIdleSeconds - Sets the time to idle for an element before it expires. Is only used if the element is not eternal. Idle time is now - last accessed time timeToLiveSeconds - Sets the time to live for an element before it expires. Is only used if the element is not eternal. TTL is now - creation time overflowToDisk - Sets whether elements can overflow to disk when the in-memory cache has reached the maxInMemory limit. --> <defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true" /> <!--Predefined caches. Add your cache configuration settings here. If you do not have a configuration for your cache a WARNING will be issued when the CacheManager starts The following attributes are required for defaultCache: name - Sets the name of the cache. This is used to identify the cache. It must be unique. maxInMemory - Sets the maximum number of objects that will be created in memory eternal - Sets whether elements are eternal. If eternal, timeouts are ignored and the element is never expired. timeToIdleSeconds - Sets the time to idle for an element before it expires. Is only used if the element is not eternal. Idle time is now - last accessed time timeToLiveSeconds - Sets the time to live for an element before it expires. Is only used if the element is not eternal. TTL is now - creation time overflowToDisk - Sets whether elements can overflow to disk when the in-memory cache has reached the maxInMemory limit. --> <!-- Sample cache named sampleCache1 This cache contains a maximum in memory of 10000 elements, and will expire an element if it is idle for more than 5 minutes and lives for more than 10 minutes. If there are more than 10000 elements it will overflow to the disk cache, which in this configuration will go to wherever java.io.tmp is defined on your system. On a standard Linux system this will be /tmp" --> <cache name="sampleCache1" maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="300" timeToLiveSeconds="600" overflowToDisk="true" /> <!-- Sample cache named sampleCache2 This cache contains 1000 elements. Elements will always be held in memory. They are not expired. --> <cache name="sampleCache2" maxElementsInMemory="1000" eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" /> --> <!-- Place configuration for your caches following --> </ehcache>
相关推荐
hibernate一级缓存和二级缓存的区别与联系
传播智客,为Spring集成的Hibernate配置二级缓存、cache.xml
Hibernate二级缓存Hibernate二级缓存Hibernate二级缓存Hibernate二级缓存Hibernate二级缓存
hibernate的一级缓存和二级缓存,hibernate的一级缓存和二级缓存,hibernate的一级缓存和二级缓存,hibernate的一级缓存和二级缓存,hibernate的一级缓存和二级缓存
hibernate 二级缓存详解hibernate 二级缓存详解hibernate 二级缓存详解hibernate 二级缓存详解hibernate 二级缓存详解hibernate 二级缓存详解hibernate 二级缓存详解hibernate 二级缓存详解hibernate 二级缓存详解
为Spring集成的Hibernate配置二级缓存
Hibernate 一级缓存和二级缓存的区别
Hibernate一级缓存、二级缓存以及查询缓存实例
hibernate5.1二级缓存包
主要讲解hibernate缓存的配置和和使用方法,以及一级缓存和二级缓存的定义和区别,和查询缓存的使用
基于springboot最新版本2.1.4.RELEASE,采用jpa为dao层框架,配置redis(redisson)为hibernate的二级缓存。
Hibernate 二级缓存
用memcached实现 Hibernate4二级缓存的实例源码。
NULL 博文链接:https://cdxs2.iteye.com/blog/1936594
基于hibernate二级缓存使用的源码实例
Spring4+Hibernate4二级缓存实例源码.
-- 查询的二级缓存配置 --> <property name="hibernate.cache.use_query_cache">true <property name="cache.provider_class">org.hibernate.cache.EhCacheProvider 4.0配置如下: <property name="hibernate...
hibernate二级缓存 ehcache
hibernate二级缓存介绍及演示代码