您好,欢迎来到五一七教育网。
搜索
您的当前位置:首页SpringBoot中注解缓存@Cacheable

SpringBoot中注解缓存@Cacheable

来源:五一七教育网
			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"
        memoryStoreEvictionPolicy="LRU">
    <persistence strategy="localTempSwap"/>
</defaultCache>
<!-- 自定义缓存策略 -->
<cache name="student"
        maxElementsInMemory="10000"
        eternal="false"
        timeToIdleSeconds="120"
        timeToLiveSeconds="120"
        maxElementsOnDisk="10000000"
        diskExpiryThreadIntervalSeconds="120"
        memoryStoreEvictionPolicy="LRU">
    <persistence strategy="localTempSwap"/>
</cache>

创建成功后 在 application.properties 中引入创建的 缓存文件

持久层的 底层 测试查询方法

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 517ttc.cn 版权所有 赣ICP备2024042791号-8

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务