1、目录
2、JetCache介绍

3、如何设计一个缓存组件?

4、SpringCache VS JetCache

5、JetCache基本使用
5.1 JetCache配置信息
- jetcache:
- statIntervalMinutes: 60
- areaInCacheName: false
- penetrationProtect: true
- enableMethodCache: true
- hiddenPackages: com.xxx.xxx,com.xxx.xxx
- local:
- default:
- type: caffeine # 支持的类型:linkedhashmap、caffeine
- limit: 100
- keyConvertor: fastjson # 支持的类型:fastjson,可自定义转换器函数
- expireAfterWriteInMillis: 600000
- expireAfterAccessInMillis: 300000
- remote:
- default:
- type: redis.lettuce # 支持的类型:redis、redis.lettuce
- keyPrefix: '系统简称:所属名字:'
- keyConvertor: fastjson
- valueEncoder: java # 支持的类型:kryo、java,可自定义编码器
- valueDecoder: java # 支持的类型:kryo、java,可自定义解码器
- expireAfterWriteInMillis: 3600000
- #readFrom: slavePreferred # 优先从Slave节点中读取
- uri: redis-sentinel://host1:26379,host2:26379,host3:26379/?sentinelMasterId=mymaster # 哨兵模式
- #uri: redis://127.0.0.1:6379/ # 单节点模式
- #mode: masterslave # 设置为主从模式
- #uri: # 集群模式
- #- redis://127.0.0.1:7000
- #- redis://127.0.0.1:7001
- #- redis://127.0.0.1:7002



5.2、JetCache使用示例





6、JetCache原理
- Cache:缓存接口,定义基本方法
- AbstractCache:抽象类,缓存接口的继承者,提供基本实现,具体实现交由不同的子类
- LinkedHashMapCache:基于LinkedHashMap设计的简易内存缓存
- CaffeineCache:基于Caffeine工具设计的内存缓存
- RedisCache:Redis实现,使用Jedis客户端
- RedisLettuceCache:Redis实现,使用Lettuce客户端
- MultiLevelCache:两级缓存,用于封装EmbeddedCache(本地缓存)和ExternalCache(远程缓存)
- RefreshCache:基于装饰器模式Decorator,提供自动刷新功能
- LazyInitCache:用于@CreateCache注解创建的缓存实例,依赖于Spring
JetCache源码入口
@EbableMethodCache -> JetCacheInterceptor
JetCacheAutoConfiguration
缓存get/put基本实现
Cache->AbstractCache->AbstractEmbeddedCache->LinkedHashMapCache
get()->GET()->do_GET()->map.get()
获取/存放 数据 -> 构建CacheResult -> 数据统计CacheState -> 缓存监控CacheMonitor
缓存过期时间的实现
被动过期:
主动过期 Cleaner:

缓存自动刷新的实现
RefreshCache


防止缓存击穿的实现
@CachePenetrationProtect -> AbstractCache.computeIfAbsentImpl() -> synchronizedLoad();

参考:
