Spring Data JPA 二级缓存设置

测试通过

<!--Ehcache-core 包 -->
<dependency>
      <groupId>net.sf.ehcache</groupId>
      <artifactId>ehcache-core</artifactId>
      <version>2.6.9</version>
</dependency>

<!--添加Hibernate-Ehcache包 -->
<dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-ehcache</artifactId>
      <version>${hibernate.version}</version>
</dependency>

添加资源文件
ehcache.xml
<?xml version="1.0" encoding="UTF-8"?>
<ehcache name="syscache">
    <diskStore path="java.io.tmpdir"/>
      <defaultCache
           maxEntriesLocalHeap="10000"
           eternal="false"
           overflowToDisk="true"
           timeToIdleSeconds="20"
           timeToLiveSeconds="60">
      </defaultCache>
</ehcache>

http://www.litianhua.net/blog/jpa-second-level-cache.html

里头
FavoriteAdd to favorites
引言:前两个月写有“Spring and JPA的框架集成和编码测试.”和“JPA Criteria查询的支持及使用.”两篇文章,其中主要包含了框架的集成和相关代码的演示。今天这篇是基于以上文章进行扩展的,主要是对二级缓存的的初级使用,以便于性能优化,但本文不涉及性能优化,只是初级的配置及使用。另外,您还可以看看,“Hibernate Cache的深入认识.”这篇文章,相信看完这篇之后,再来看本篇,会游刃有余,印象更加的深刻。

如果您没有看过“Spring and JPA的框架集成和编码测试.”及“JPA Criteria查询的支持及使用.”两篇文章,建议先去看一下。以下的配置和代码演示,都是基于这两篇中的演示代码。

猜你喜欢

转载自tangzongyun.iteye.com/blog/2386963