Class ReadThroughAtlassianCache<K,V>
- All Implemented Interfaces:
ReadThroughCache<K,
V>
ReadThroughCache
backed by an atlassian-cache Cache
.- Since:
- 7.5
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <K,
V> ReadThroughAtlassianCache<K, V> This is essentially an extension method forCache
.Retrieves multiple values for the given keys.void
Removs the cache entry for the given key.void
Removes all cache entries.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.atlassian.confluence.impl.cache.ReadThroughCache
get
-
Constructor Details
-
ReadThroughAtlassianCache
-
-
Method Details
-
create
public static <K,V> ReadThroughAtlassianCache<K,V> create(com.atlassian.cache.CacheFactory atlassianCacheFactory, CoreCache cacheName) -
getBulk
Description copied from interface:ReadThroughCache
Retrieves multiple values for the given keys. Any entries not already present in the cache will be supplied via the delegate loader.- Specified by:
getBulk
in interfaceReadThroughCache<K,
V>
-
removeAll
public void removeAll()Description copied from interface:ReadThroughCache
Removes all cache entries.- Specified by:
removeAll
in interfaceReadThroughCache<K,
V>
-
remove
Description copied from interface:ReadThroughCache
Removs the cache entry for the given key.- Specified by:
remove
in interfaceReadThroughCache<K,
V>
-
get
This is essentially an extension method forCache
.It provides an overloaded varant of
ReadThroughCache.get(Object, com.atlassian.cache.Supplier)
which also takes a predicate which will be used to filter values both (a) after they're loaded from the valueSupplier, and (b) after they're retrieved from the cache.This gives us the concept of the "uncacheable value" as well as the "stale value". These are both caching anti-patterns, but the older code in Confluence is really quite attached to these ideas and doesn't want to give them up, doesn't want to let them down, doesn't want to turn around and forget them.
Note also that the atlassian-cache API has no such concepts, i.e. the value supplier cannot return null, and whatever the supplier returns will always be added to the cache. In order to work around this, we use exceptions to escape from the stack (I know, I know, don't @ me), which are then caught and decoded. It's butt ugly, but it's contained within this doozy of a method and won't leak out.
- Specified by:
get
in interfaceReadThroughCache<K,
V> - Parameters:
key
- the key to resolve in the cachevalueSupplier
- ASupplier
which will be called if there is no value in the cache (may return null).valueTester
- APredicate
that will be used to test the validity of any value in the cache or loaded from the supplier- Returns:
- the cached value, or the value which was loaded from the supplier (may be null)
-