**
springboot+緩存
1:pom文件配置依賴
org.springframework.boot
spring-boot-starter-cache
2:在springboot的启动类上,加上此注解@EnableCaching,全局开缓存,默认缓存框架是ConcurrentMap.
3:在mapper文件中使用
@Cacheable(value=“users”,key="#id")
public User getUserById(Integer id);
ehcache配置
1:pom.xml加入依赖
net.sf.ehcache
ehcache
2:建立ehcache.xml配置文件
<diskStore path="java.io.tmpdir"/>
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
maxElementsOnDisk="10000000"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU">
<persistence strategy="localTempSwap"/>
</defaultCache>
<cache name="users"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
maxElementsOnDisk="10000000"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU">
<persistence strategy="localTempSwap"/>
</cache>
3:application.yml中配置路徑
spring:
cache:
ehcache:
config: ehcache.xm