-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Cache
Ben Manes edited this page Mar 22, 2015
·
8 revisions
A Cache is similar to ConcurrentMap, but not quite the same. The most fundamental difference is that a ConcurrentMap persists all elements that are added to it until they are explicitly removed. A Cache
on the other hand is generally configured to evict entries automatically, in order to constrain its memory footprint. In some cases a LoadingCache
or AsyncLoadingCache
can be useful even if it doesn't evict entries, due to its automatic cache loading.
Caffeine provide flexible construction to create a cache with any combination of the following features:
- automatic loading of entries into the cache, optionally asynchronously
- least-recently-used eviction when a maximum size is exceeded
- time-based expiration of entries, measured since last access or last write
- keys automatically wrapped in [weak][2] references
- values automatically wrapped in [weak][2] or [soft][3] references
- notification of evicted (or otherwise removed) entries
- accumulation of cache access statistics