Class ThreadScopedCaches
- java.lang.Object
-
- com.atlassian.bamboo.utils.scopedcaches.ThreadScopedCaches
-
- Direct Known Subclasses:
ThreadScopedCaches
public class ThreadScopedCaches extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ThreadScopedCaches.Key<K,V>
Interface for keys for this cache.
-
Constructor Summary
Constructors Constructor Description ThreadScopedCaches()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <K,V>
VgetValue(ThreadScopedCaches.Key<K,V> cacheKey, K key, Supplier<? extends V> supplier)
Returns the value called bysupplier.get
or a previously cached value.static void
inCachingScope(Runnable runnable)
static <T> T
inCachingScope(Supplier<T> supplier)
static <K,V>
ThreadScopedCaches.Key<K,V>makeKey(Class<?> aClass)
The returned keys rely on identity comparison.
-
-
-
Method Detail
-
getValue
public static <K,V> V getValue(ThreadScopedCaches.Key<K,V> cacheKey, K key, Supplier<? extends V> supplier)
Returns the value called bysupplier.get
or a previously cached value. The cache is scoped to the current request and will be cleared at the end of the request. No caching will apply if invoked outside a request. No caching will apply within a mutative request.- Parameters:
cacheKey
- a key to identify the cachekey
- a sub-key to cache the specific value undersupplier
- will be called to return the object the- Returns:
- the result of supplier.get()
- Throws:
RuntimeException
- if thrown by supplier.get()
-
inCachingScope
public static void inCachingScope(Runnable runnable)
-
inCachingScope
public static <T> T inCachingScope(Supplier<T> supplier)
-
makeKey
public static <K,V> ThreadScopedCaches.Key<K,V> makeKey(Class<?> aClass)
The returned keys rely on identity comparison. You can have multiple such keys per class but each Key instance creates a separate cache.
-
-