|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.atlassian.jira.util.cache.ManagedCache<K,V>
K
- The key of the cache.V
- The values of the cache.public final class ManagedCache<K,V>
A concurrent, thread-safe cache suitible for use with cached Store/Persister or Manager implementations.
The cache is filled by calls toget(Object)
by the use of a factory.
The cache for a given key can be invalidated with remove(Object)
, or the whole
invalidated with clear()
.
Important features:
get(Object)
.
public class CachedFooStore implements FooStore { private final ManagedCache<FooKey, Foo> cache = ManagedCache.newManagedCache( new Function<FooKey, Foo>() { public Foo apply(@Nullable FooKey key) { return delegate.get(key); } } ); ... public Foo getFoo(FooKey key) { return cache.get(key); } public void deleteFoo(FooKey key) { try { delegate.deleteFoo(key); } finally { cache.remove(key); } } public void updateFoo(FooKey key, Foo foo) { try { delegate.updateFoo(key, foo); } finally { cache.remove(key); } } public Foo createFoo(FooKey key, Foo foo) { try { return delegate.createFoo(key, foo); } finally { cache.remove(key); } } }
Method Summary | ||
---|---|---|
void |
clear()
Remove all items from the cache. |
|
V |
get(K arg)
Retrieve an item from the cache, or create it if not already in the cache. |
|
static
|
newManagedCache(com.google.common.base.Function<K,V> factory)
Create a new cache. |
|
static
|
newManagedCache(com.google.common.base.Function<K,V> factory,
com.google.common.base.Function<K,T> keyFactory)
Create a new cache, where get/remove should be in terms of K , but the
internal map should be keyed in terms of a value T (derived from K
via keyFactory ). |
|
void |
remove(K a)
Remove an item from the cache. |
|
int |
size()
Indicitive size of cache. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static <K,V,T> ManagedCache<K,V> newManagedCache(com.google.common.base.Function<K,V> factory, com.google.common.base.Function<K,T> keyFactory)
K
, but the
internal map should be keyed in terms of a value T
(derived from K
via keyFactory
).
K
- Keys of the cache.V
- Values of the cache.T
- Type of the keys in the internal map.factory
- factory for creating a new V
when it is missing from the cache.keyFactory
- function for deriving the map key V
from K
public static <K,V> ManagedCache<K,V> newManagedCache(com.google.common.base.Function<K,V> factory)
K
- Keys of the cache.V
- Values of the cache.factory
- factory for creating a new V
when it is missing from the cache.public V get(K arg)
public void remove(K a)
public void clear()
public int size()
get(Object)
are in progress, and they call the factory and it returns null,
then those nulls may be included in this count even though they will not be
in the cache when the get()
eventually returns.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |