Top Description Constructors Methods
org.glassfish.hk2.utilities.cache

public abstract Class LRUCache<K, V>

extends Object
Class Inheritance
Known Direct Subclasses
org.glassfish.hk2.utilities.cache.internal.LRUCacheCheapRead
Type Parameters
<K>
The key type for this cache
<V>
The value type for this cache
Imports
org.glassfish.hk2.utilities.cache.internal.LRUCacheCheapRead

A cache that contains a certain number of entries, and whose oldest accessed entries are removed when removal is necessary.
Author
jwells

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static <K, V> LRUCache<K, V>

Returns:

An LRUCache that can be used to quickly retrieve objects
createCache
(int
The maximum number of entries in the cache, must be greater than 2
maxCacheSize
)

Creates a cache with the given maximum cache size

public abstract V

Returns:

The value associated with the key, or null if there is no such value
get
(K
Must be a non-null key, appropriate for use as the key to a hash map
key
)

Returns the value associated with the given key.

public abstract int

Returns:

The maximum number of entries that will be stored in this cache
getMaxCacheSize
()

Returns the maximum number of entries that will be stored in this cache

public abstract CacheEntry

Returns:

A cache entry that can be used to remove this entry from the cache. Will not return null
put
(K
Must be a non-null key, appropriate for use as the key to a hash map
key
,
V
Must be a non-null value
value
)

Adds the given key and value pair into the cache

public abstract void
releaseCache()

Clears all entries in the cache, for use when a known event makes the cache incorrect

public abstract void
releaseMatching(CacheKeyFilter<K>
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
filter
)

This method will remove all cache entries for which this filter matches

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

LRUCacheback to summary
public LRUCache()

Method Detail

createCacheback to summary
public static <K, V> LRUCache<K, V> createCache(int maxCacheSize)

Creates a cache with the given maximum cache size

Parameters
maxCacheSize:int

The maximum number of entries in the cache, must be greater than 2

Returns:LRUCache<K, V>

An LRUCache that can be used to quickly retrieve objects

getback to summary
public abstract V get(K key)

Returns the value associated with the given key. If there is no value, returns null

Parameters
key:K

Must be a non-null key, appropriate for use as the key to a hash map

Returns:V

The value associated with the key, or null if there is no such value

getMaxCacheSizeback to summary
public abstract int getMaxCacheSize()

Returns the maximum number of entries that will be stored in this cache

Returns:int

The maximum number of entries that will be stored in this cache

putback to summary
public abstract CacheEntry put(K key, V value)

Adds the given key and value pair into the cache

Parameters
key:K

Must be a non-null key, appropriate for use as the key to a hash map

value:V

Must be a non-null value

Returns:CacheEntry

A cache entry that can be used to remove this entry from the cache. Will not return null

releaseCacheback to summary
public abstract void releaseCache()

Clears all entries in the cache, for use when a known event makes the cache incorrect

releaseMatchingback to summary
public abstract void releaseMatching(CacheKeyFilter<K> filter)

This method will remove all cache entries for which this filter matches

Parameters
filter:CacheKeyFilter<K>

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