GitXplorerGitXplorer
s

BothCache

public
6 stars
0 forks
0 issues

Commits

List of commits on branch main.
Verified
5992c8654cefe07354a5cf087e0570c800a48323

Update README.md

ssupalle committed 3 years ago
Verified
f3f74940b2c0f089618eb9248e9d4bae51d01d52

Update README.md

ssupalle committed 3 years ago
Verified
3442064a05c6512a0e43d92086fdb72affec2e41

Update README.md

ssupalle committed 3 years ago
Verified
ece0766cab71dc2d52e58eb51c39219b5655e0a8

Update README.md

ssupalle committed 3 years ago
Verified
eb1f2a30ac785f5733bd7ce27fe1dbc6a55456d4

Update README.md

ssupalle committed 3 years ago
Verified
8b298d423ce064930197ffc532ae21a9fab53a1c

Update BothCacheConfig.java

ssupalle committed 3 years ago

README

The README file for this repository.

BothCache

一个springboot项目里的二级缓存实现:DEMO

特点:

  1. 简单,只需要往项目里粘贴这类,目前的版本连jar包都不需要引入。
  2. 基于SpringCache,所以完全兼容现在大量使用的@CacheConfig和@Cacheable等注解

使用方法:

前置条件:首先项目里得有SpringData Redis和caffeine,最好是已经用着了,没有就加一下依赖。

步骤1:往项目里添加BothCacheConfig类,包名请换成你自己项目里的包名:

步骤2:application.yml 里添加配置

spring.cache.caffeine.spec: expireAfterWrite=5s # 缓存写后多长时间过期

步骤3:需要二级缓存的地方使用二级缓存,在注解里加上 cacheResolver = "bothCacheResolver" 即可:

  1. @CacheConfig 里添加 cacheResolver = "bothCacheResolver"
@CacheConfig(cacheNames = "dict", cacheResolver = "bothCacheResolver")

如图: @CacheConfig里使用.png

  1. @Cacheable里添加cacheResolver = "bothCacheResolver"
@Cacheable(key = "#p0", cacheResolver = "bothCacheResolver")

如图: @Cacheable里使用.png

其它注解一致。

最后:请原谅我没写注释

That it.