DevilKing's blog

冷灯看剑,剑上几分功名?炉香无需计苍生,纵一穿烟逝,万丈云埋,孤阳还照古陵

0%

Jetcache intro

原repo

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中?

1
2
3
4
result.future().thenRun(() -> {
CachePutAllEvent event = new CachePutAllEvent(this, System.currentTimeMillis() - t, map, result);
notify(event);
});

采用event的方式,来进行多线程消费?

后续的monitor代码

1
2
3
4
5
6
7
8
CacheResult状态

public void notify(CacheEvent e) {
List<CacheMonitor> monitors = config().getMonitors();
for (CacheMonitor m : monitors) {
m.afterOperation(e);
}
}

定义innerMap interface

然后每一种cache自己去实现这一部分,独有的部分

开启另一个线程去refresh

1
2
3
4
5
6
7
8
9
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;
});