public final class ReadThroughAtlassianCache<K,V> extends Object implements ReadThroughCache<K,V>
ReadThroughCache
backed by an atlassian-cache Cache
.Constructor and Description |
---|
ReadThroughAtlassianCache(com.atlassian.cache.Cache<K,V> delegate) |
Modifier and Type | Method and Description |
---|---|
static <K,V> ReadThroughAtlassianCache<K,V> |
create(com.atlassian.cache.CacheFactory atlassianCacheFactory,
CoreCache cacheName) |
V |
get(K key,
Supplier<V> valueSupplier,
Predicate<V> valueTester)
This is essentially an extension method for
Cache . |
Map<K,V> |
getBulk(Set<K> keys,
Function<Set<K>,Map<K,V>> valuesLoader)
Retrieves multiple values for the given keys.
|
void |
remove(K key)
Removs the cache entry for the given key.
|
void |
removeAll()
Removes all cache entries.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
get
public static <K,V> ReadThroughAtlassianCache<K,V> create(com.atlassian.cache.CacheFactory atlassianCacheFactory, CoreCache cacheName)
public Map<K,V> getBulk(Set<K> keys, Function<Set<K>,Map<K,V>> valuesLoader)
ReadThroughCache
getBulk
in interface ReadThroughCache<K,V>
public void removeAll()
ReadThroughCache
removeAll
in interface ReadThroughCache<K,V>
public void remove(K key)
ReadThroughCache
remove
in interface ReadThroughCache<K,V>
public V get(K key, Supplier<V> valueSupplier, Predicate<V> valueTester)
Cache
.
It provides an overloaded varant of Cache.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.
get
in interface ReadThroughCache<K,V>
key
- the key to resolve in the cachevalueSupplier
- A Supplier
which will be called if there is no value in the cache (may return null).valueTester
- A Predicate
that will be used to test the validity of any value in the cache or loaded from the supplierCopyright © 2003–2021 Atlassian. All rights reserved.