ben-manes / caffeine

A high performance caching library for Java
Apache License 2.0
15.68k stars 1.59k forks source link

Remote cache support #1332

Closed mehrdad2000 closed 9 months ago

mehrdad2000 commented 9 months ago

Hi Does Caffeine support remote cache?

Thanks

ben-manes commented 9 months ago

Caffeine can be integrated with one, but does not provide a remote cache functionality.

A Cache.get can use a CacheLoader or a mapping function to fetch the entry atomically. That can load from your remote cache prior to the system of record (e.g. memcached else db). Relatedly, a refresh can call this for reloading proactively before a popular entry expires.

The asMap().compute methods let you write into the cache and a secondary store. This way your mapping function can update both caches if desired.

How you broadcast the invalidation, the remote cache topology, etc. is your application's decision.

Caffeine was adopted as the local cache by Oracle Coherence. Redhat Infinispan, and Redisson. Those are separate projects that manage their stack. Many do it themselves as described above, such as in this recent DoorDash article or as like Twitter's CaffeineMemcacheClient.