org.glassfish.hk2.utilities.cache
Class LRUCache<K,V>

java.lang.Object
  extended by org.glassfish.hk2.utilities.cache.LRUCache<K,V>
Direct Known Subclasses:
LRUCacheImpl

public abstract class LRUCache<K,V>
extends Object

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

Author:
jwells

Constructor Summary
LRUCache()
           
 
Method Summary
static
<K,V> LRUCache<K,V>
createCache(int maxCacheSize)
          Creates a cache with the given maximum cache size
abstract  V get(K key)
          Returns the value associated with the given key.
abstract  int getMaxCacheSize()
          Returns the maximum number of entries that will be stored in this cache
abstract  CacheEntry put(K key, V value)
          Adds the given key and value pair into the cache
abstract  void releaseCache()
          Clears all entries in the cache, for use when a known event makes the cache incorrect
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LRUCache

public LRUCache()
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 map
value - 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


Copyright © 2012 Oracle Corporation. All Rights Reserved.