1

My cache is built with writer:

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

In my test, I'm loading 10 items and then waiting (with an infinite loop + sleep).

The problem is that write() never get called, even after calling cleanUp()

Why isn't write() been triggered?

Ori Marko
  • 56,308
  • 23
  • 131
  • 233
IsaacLevon
  • 2,260
  • 4
  • 41
  • 83

1 Answers1

2

Writer called only when entry is changed

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

You aren't adding/removing entries.

Ori Marko
  • 56,308
  • 23
  • 131
  • 233
  • I see, thanks. So when loading an item for the first time, I'll need to write it to DB myself, manually. Would that be a correct approach? – IsaacLevon Nov 18 '19 at 14:25
  • @yaseco read in link about write mode as **write-through cache the operations are performed synchronously and the cache will only be updated if the writer completes successfully** – Ori Marko Nov 18 '19 at 14:29
  • I understand now, I shall use `put()` to trigger `write()` – IsaacLevon Nov 18 '19 at 14:38