Package org.kairosdb.bigqueue.cache
Class LRUCacheImpl<K,V extends Closeable>
- java.lang.Object
-
- org.kairosdb.bigqueue.cache.LRUCacheImpl<K,V>
-
- Type Parameters:
K- keyV- value
- All Implemented Interfaces:
ILRUCache<K,V>
public class LRUCacheImpl<K,V extends Closeable> extends Object implements ILRUCache<K,V>
Simple and thread-safe LRU cache implementation, supporting time to live and reference counting for entry. in current implementation, entry expiration and purge(mark and sweep) is triggered by put operation, and resource closing after mark and sweep is done in async way.- Author:
- bulldog
-
-
Field Summary
Fields Modifier and Type Field Description static longDEFAULT_TTL
-
Constructor Summary
Constructors Constructor Description LRUCacheImpl(Clock clock)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidCloseExecutorService()Shutdown the internal ExecutorService, Call this only after you have closed your bigqueue instance.Vget(K key)Get a cached resource with specific key This call will increment the reference counter of the keyed resource.Collection<V>getValues()All values cachedvoidput(K key, V value)Put a keyed resource with default ttl into the cache This call will increment the reference counter of the keyed resource.voidput(K key, V value, long ttlInMilliSeconds)Put a keyed resource with specific ttl into the cache This call will increment the reference counter of the keyed resource.voidrelease(K key)Release the cached resource with specific key This call will decrement the reference counter of the keyed resource.Vremove(K key)Remove the resource with specific key from the cache and close it synchronously afterwards.voidremoveAll()Remove all cached resource from the cache and close them asynchronously afterwards.intsize()The size of the cache, equals to current total number of cached resources.
-
-
-
Field Detail
-
DEFAULT_TTL
public static final long DEFAULT_TTL
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
LRUCacheImpl
public LRUCacheImpl(Clock clock)
-
-
Method Detail
-
CloseExecutorService
public static void CloseExecutorService()
Shutdown the internal ExecutorService, Call this only after you have closed your bigqueue instance.
-
put
public void put(K key, V value, long ttlInMilliSeconds)
Description copied from interface:ILRUCachePut a keyed resource with specific ttl into the cache This call will increment the reference counter of the keyed resource.
-
put
public void put(K key, V value)
Description copied from interface:ILRUCachePut a keyed resource with default ttl into the cache This call will increment the reference counter of the keyed resource.
-
get
public V get(K key)
Description copied from interface:ILRUCacheGet a cached resource with specific key This call will increment the reference counter of the keyed resource.
-
release
public void release(K key)
Description copied from interface:ILRUCacheRelease the cached resource with specific key This call will decrement the reference counter of the keyed resource.
-
size
public int size()
Description copied from interface:ILRUCacheThe size of the cache, equals to current total number of cached resources.
-
removeAll
public void removeAll() throws IOExceptionDescription copied from interface:ILRUCacheRemove all cached resource from the cache and close them asynchronously afterwards.
-
remove
public V remove(K key) throws IOException
Description copied from interface:ILRUCacheRemove the resource with specific key from the cache and close it synchronously afterwards.
-
-