Package ca.uhn.fhir.jpa.util
Class MemoryCacheService
java.lang.Object
ca.uhn.fhir.jpa.util.MemoryCacheService
This class acts as a central spot for all of the many Caffeine caches we use in HAPI FHIR.
The API is super simplistic, and caches are all 1-minute, max 10000 entries for starters. We could definitely add nuance to this, which will be much easier now that this is being centralized. Some logging/monitoring would be good too.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
static class
static class
static class
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected <K,
T> T doGet
(MemoryCacheService.CacheEnum theCache, K theKey, Function<K, T> theSupplier) protected <K,
V> Map <K, V> doGetAllPresent
(MemoryCacheService.CacheEnum theCache, Collection<K> theKeys) protected <K,
V> V doGetIfPresent
(MemoryCacheService.CacheEnum theCache, K theKey) protected <K,
V> void doPut
(MemoryCacheService.CacheEnum theCache, K theKey, V theValue) <K,
T> T get
(MemoryCacheService.CacheEnum theCache, K theKey, Function<K, T> theSupplier) <K,
V> Map <K, V> getAllPresent
(MemoryCacheService.CacheEnum theCache, Collection<K> theKeys) long
getEstimatedSize
(MemoryCacheService.CacheEnum theCache) <K,
V> V getIfPresent
(MemoryCacheService.CacheEnum theCache, K theKey) <K,
T> T getThenPutAfterCommit
(MemoryCacheService.CacheEnum theCache, K theKey, Function<K, T> theSupplier) Fetch an item from the cache if it exists, and use the loading function to obtain it otherwise.void
void
invalidateCaches
(MemoryCacheService.CacheEnum... theCaches) <K,
V> void put
(MemoryCacheService.CacheEnum theCache, K theKey, V theValue) <K,
V> void putAfterCommit
(MemoryCacheService.CacheEnum theCache, K theKey, V theValue) This method registers a transaction synchronization that puts an entry in the cache if and when the current database transaction successfully commits.
-
Constructor Details
-
MemoryCacheService
-
-
Method Details
-
get
-
doGet
protected <K,T> T doGet(MemoryCacheService.CacheEnum theCache, K theKey, Function<K, T> theSupplier) -
getThenPutAfterCommit
public <K,T> T getThenPutAfterCommit(MemoryCacheService.CacheEnum theCache, K theKey, Function<K, T> theSupplier) Fetch an item from the cache if it exists, and use the loading function to obtain it otherwise.This method will put the value into the cache using
putAfterCommit(CacheEnum, Object, Object)
. -
getIfPresent
-
doGetIfPresent
-
put
-
doPut
-
putAfterCommit
This method registers a transaction synchronization that puts an entry in the cache if and when the current database transaction successfully commits. If the transaction is rolled back, the key+value passed into this method will not be added to the cache.This is useful for situations where you want to store something that has been resolved in the DB during the current transaction, but it's not yet guaranteed that this item will successfully save to the DB. Use this method in that case in order to avoid cache poisoning.
-
getAllPresent
-
doGetAllPresent
protected <K,V> Map<K,V> doGetAllPresent(MemoryCacheService.CacheEnum theCache, Collection<K> theKeys) -
invalidateAllCaches
-
getEstimatedSize
-
invalidateCaches
-