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
A cache that contains a certain number of entries, and whose oldest accessed
entries are removed when removal is necessary.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <K,
V> LRUCache <K, V> createCache
(int maxCacheSize) Creates a cache with the given maximum cache sizeabstract V
Returns the value associated with the given key.abstract int
Returns the maximum number of entries that will be stored in this cacheabstract CacheEntry
Adds the given key and value pair into the cacheabstract void
Clears all entries in the cache, for use when a known event makes the cache incorrectabstract void
releaseMatching
(CacheKeyFilter<K> filter) This method will remove all cache entries for which this filter matches
-
Constructor Details
-
LRUCache
public LRUCache()
-
-
Method Details
-
createCache
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
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
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
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
-