Hibernate Ehcache 配置

hibernate 默认使用 ehcache 缓存策略
ehcache 配置

<?xml version="1.0" encoding="UTF-8"?>
<ehcache>
<!--<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd">-->
    <!--
    Subdirectories can be specified below the property e.g. java.io.tmpdir/one
 mac, ubuntu java.io.tmpdir = /tmp
    -->
    <diskStore path="java.io.tmpdir"/>

    <!--
    Mandatory Default Cache configuration. These settings will be applied to caches
    created programmtically using CacheManager.add(String cacheName)
    -->
    <defaultCache
            maxElementsInMemory="10000"
            eternal="false"
            timeToIdleSeconds="120"
            timeToLiveSeconds="120"
            overflowToDisk="true"
            maxElementsOnDisk="10000000"
            diskPersistent="false"
            diskExpiryThreadIntervalSeconds="120"
            memoryStoreEvictionPolicy="LRU"
    />

    <cache name="org.hibernate.cache.spi.UpdateTimestampsCache"
           maxElementsInMemory="5000"
           eternal="true"
           overflowToDisk="false" />
    <cache name="org.hibernate.cache.internal.StandardQueryCache"
           maxElementsInMemory="10000"
           eternal="false"
           timeToLiveSeconds="120"
           overflowToDisk="false" />


    <cache name="javaClassName" maxElementsInMemory="2000" eternal="false"
           timeToIdleSeconds="120" timeToLiveSeconds="120"
           overflowToDisk="false" />

</ehcache>

hibernate 配置

        <!-- 开启查询缓存 把 hibernate query 中 cacheable 参数 设置成 true 就可以使用缓存了 -->
        <property name="hibernate.cache.use_query_cache">true</property>
        <!-- 开启二级缓存 -->
        <property name="hibernate.cache.use_second_level_cache">true</property>
        <!-- 高速缓存提供程序 -->
        <!-- 由于spring也使用了Ehcache, 保证双方都使用同一个缓存管理器 -->
        <property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory</property>

Spring 中 ehcache 配置

    <!-- cacheManager, 指定ehcache.xml的位置 -->
    <bean id="cacheManagerEhcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
        <property name="configLocation">
            <value>classpath:/ehcache.xml</value>
        </property>
        <property name="shared" value="true"/>
    </bean>
    <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager"  p:cacheManager-ref="cacheManagerEhcache" />

说明:该配置是在已经整合完 Spring 和 Hibernate 前提下进行的

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值