Class LRUCache<K,V>
- java.lang.Object
-
- org.glassfish.hk2.utilities.cache.LRUCache<K,V>
-
- Type Parameters:
K- The key type for this cacheV- The value type for this cache
- Direct Known Subclasses:
LRUCacheCheapRead
public abstract class LRUCache<K,V> extends java.lang.ObjectA cache that contains a certain number of entries, and whose oldest accessed entries are removed when removal is necessary.
-
-
Constructor Summary
Constructors Constructor Description LRUCache()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static <K,V>
LRUCache<K,V>createCache(int maxCacheSize)Creates a cache with the given maximum cache sizeabstract Vget(K key)Returns the value associated with the given key.abstract intgetMaxCacheSize()Returns the maximum number of entries that will be stored in this cacheabstract CacheEntryput(K key, V value)Adds the given key and value pair into the cacheabstract voidreleaseCache()Clears all entries in the cache, for use when a known event makes the cache incorrectabstract voidreleaseMatching(CacheKeyFilter<K> filter)This method will remove all cache entries for which this filter matches
-
-
-
Method Detail
-
createCache
public static <K,V> LRUCache<K,V> createCache(int maxCacheSize)
Creates a cache with the given maximum cache size- Parameters:
maxCacheSize- The maximum number of entries in the cache, must be greater than 2- Returns:
- An LRUCache that can be used to quickly retrieve objects
-
get
public abstract V get(K key)
Returns the value associated with the given key. If there is no value, returns null- Parameters:
key- Must be a non-null key, appropriate for use as the key to a hash map- Returns:
- The value associated with the key, or null if there is no such value
-
put
public abstract CacheEntry put(K key, V value)
Adds the given key and value pair into the cache- Parameters:
key- Must be a non-null key, appropriate for use as the key to a hash mapvalue- Must be a non-null value- Returns:
- A cache entry that can be used to remove this entry from the cache. Will not return null
-
releaseCache
public abstract void releaseCache()
Clears all entries in the cache, for use when a known event makes the cache incorrect
-
getMaxCacheSize
public abstract int getMaxCacheSize()
Returns the maximum number of entries that will be stored in this cache- Returns:
- The maximum number of entries that will be stored in this cache
-
releaseMatching
public abstract void releaseMatching(CacheKeyFilter<K> filter)
This method will remove all cache entries for which this filter matches- Parameters:
filter- Entries in the cache that match this filter will be removed from the cache. If filter is null nothing will be removed from the cache
-
-