EhCache是一个比较成熟的Java缓存框架,最早从hibernate发展而来, 是进程中的缓存系统,它提供了用内存,磁盘文件存储,以及分布式存储方式等多种灵活的cache管理方案,快速简单。
Springboot对ehcache的使用非常支持,所以在Springboot中只需做些配置就可使用,且使用方式也简易。
在你的项目上配置以下几步即可使用
首先,老规矩,pom.xml加依赖;
org.springframework.boot
spring-boot-starter-cache
net.sf.ehcache
ehcache
第二步,创建ehcache.xml配置文件
位置:classpath目录下,即src/main/resources/ehcache.xml
文件内容开发的时候可参考第一步导入的jar包,具体在哪呢,看下面:
再看代码:
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
maxElementsOnDisk="10000000"
diskExpiryThreadIntervalSeconds=&#