Package com.gengoai.cache
Class LRUCache<K,V>
- java.lang.Object
-
- com.gengoai.cache.LRUCache<K,V>
-
- Type Parameters:
K
- the key type parameterV
- the value type parameter
- All Implemented Interfaces:
Cache<K,V>
- Direct Known Subclasses:
AutoCalculatingLRUCache
public class LRUCache<K,V> extends Object implements Cache<K,V>
Last-Recently-Used Cache with bounded size.- Author:
- David B. Bracewell
-
-
Constructor Summary
Constructors Constructor Description LRUCache(int maxSize)
Instantiates a new LRU cache with given max size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
containsKey(K key)
Determines if a key is in the cache or notV
get(K key)
Gets the value associated with a keyV
get(K key, SerializableSupplier<? extends V> supplier)
Gets the value associated with the given key when available and if not available calculates and stores the value using the given supplier.void
invalidate(K key)
Removes a single keyvoid
invalidateAll()
Clears the cachevoid
put(K key, V value)
Adds a key value pair to the cache overwriting any value that is therelong
size()
The number of items cached.String
toString()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.gengoai.cache.Cache
invalidateAll, isEmpty
-
-
-
-
Method Detail
-
containsKey
public boolean containsKey(K key)
Description copied from interface:Cache
Determines if a key is in the cache or not- Specified by:
containsKey
in interfaceCache<K,V>
- Parameters:
key
- The key to check- Returns:
- True if the key is in the cache, False if not
-
get
public V get(K key)
Description copied from interface:Cache
Gets the value associated with a key
-
get
public V get(K key, SerializableSupplier<? extends V> supplier)
Description copied from interface:Cache
Gets the value associated with the given key when available and if not available calculates and stores the value using the given supplier.
-
invalidate
public void invalidate(K key)
Description copied from interface:Cache
Removes a single key- Specified by:
invalidate
in interfaceCache<K,V>
- Parameters:
key
- The key to remove
-
invalidateAll
public void invalidateAll()
Description copied from interface:Cache
Clears the cache- Specified by:
invalidateAll
in interfaceCache<K,V>
-
put
public void put(K key, V value)
Description copied from interface:Cache
Adds a key value pair to the cache overwriting any value that is there
-
size
public long size()
Description copied from interface:Cache
The number of items cached.
-
-