SpringBoot中注解缓存 @Cacheable 及控制台展示 执行 SQL 查看是否缓存成功
SpringBoot 的maven的项目中,首先在 pom.xml文件中 注入 Spring Boot 缓存支持启动器 及 Ehcache 坐标
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<!-- Ehcache 坐标 -->
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
创建 Ehcache 的配置文件,文件名:ehcache.xml 位置:src/main/resources/ehcache.xml
<diskStore path="java.io.tmpdir"/>
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
maxElementsOnDisk="10000000"
diskExpiryThreadIntervalSeconds="120