咖啡因缓存:永远不会调用 write()

Caffeine cache: write() never get called

我的缓存是用 writer:

构建的
appsCache = Caffeine.newBuilder()
        .writer(this)
        .maximumSize(10)
        .expireAfterWrite(Duration.ofSeconds(64000))
        .build(this);

在我的测试中,我正在加载 10 个项目然后等待(无限循环 + 睡眠)。

问题是 write() 永远不会被调用,即使在调用 cleanUp()

之后也是如此

为什么 write() 没有被触发?

Writer 仅在更改条目时调用

The CacheWriter is notified when an entry is created, mutated, or removed. A mapping that is loaded (e.g. LoadingCache.get), reloaded (e.g. LoadingCache.refresh), or computed (e.g. Map.computeIfPresent) is not communicated

你不是 adding/removing 个条目。