工程创建完成后,引入 Ehcache 的依赖,Ehcache 目前有两个版本:
这里采用第二个,在 pom.xml 文件中,引入 Ehcache 依赖:
org.springframework.boot
spring-boot-starter-cache
org.springframework.boot
spring-boot-starter-web
net.sf.ehcache
ehcache
2.10.6
在 resources 目录下,添加 ehcache 的配置文件 ehcache.xml ,文件内容如下:
<defaultCache
maxElementsInMemory=“10000”
eternal=“false”
timeToIdleSeconds=“120”
timeToLiveSeconds=“120”
overflowToDisk=“false”
diskPersistent=“false”
diskExpiryThreadIntervalSeconds=“120”
/>
<cache name=“user”
maxElementsInMemory=“10000”
eternal=“true”
overflowToDisk=“true”