一个springboot项目里的二级缓存实现:DEMO
- 简单,只需要往项目里粘贴这类,目前的版本连jar包都不需要引入。
- 基于SpringCache,所以完全兼容现在大量使用的@CacheConfig和@Cacheable等注解
步骤1:往项目里添加BothCacheConfig类,包名请换成你自己项目里的包名:
spring.cache.caffeine.spec: expireAfterWrite=5s # 缓存写后多长时间过期
- @CacheConfig 里添加
cacheResolver = "bothCacheResolver"
@CacheConfig(cacheNames = "dict", cacheResolver = "bothCacheResolver")
- @Cacheable里添加
cacheResolver = "bothCacheResolver"
@Cacheable(key = "#p0", cacheResolver = "bothCacheResolver")
其它注解一致。