The annotation in JetCache supports native TTL, two level caching, and distributed automatically refreshment, also you can operate Cache instance by hand code. Presently There are four implements: RedisCache, TairCache(not open source on github), CaffeineCache (in memory), a simple LinkedHashMapCache (in memory).
所谓的two level caching?
主要是在multiLevelCache中?
result.future().thenRun(() -> {
CachePutAllEvent event = new CachePutAllEvent(this, System.currentTimeMillis() - t, map, result);
notify(event);
});
采用event的方式,来进行多线程消费?
后续的monitor代码
CacheResult状态
public void notify(CacheEvent e) {
List<CacheMonitor> monitors = config().getMonitors();
for (CacheMonitor m : monitors) {
m.afterOperation(e);
}
}
定义innerMap interface
然后每一种cache自己去实现这一部分,独有的部分
开启另一个线程去refresh
RefreshTask refreshTask = taskMap.computeIfAbsent(taskId, tid -> {
logger.debug("add refresh task. interval={}, key={}", refreshMillis , key);
RefreshTask task = new RefreshTask(taskId, key, loader);
task.lastAccessTime = System.currentTimeMillis();
ScheduledFuture<?> future = JetCacheExecutor.heavyIOExecutor().scheduleWithFixedDelay(
task, refreshMillis, refreshMillis, TimeUnit.MILLISECONDS);
task.future = future;
return task;
});