org.rimudb.util
Class LRUCache2<K,V>

java.lang.Object
  extended by org.rimudb.util.LRUCache2<K,V>

public class LRUCache2<K,V>
extends java.lang.Object


Constructor Summary
LRUCache2(int cacheSize)
          Creates a new LRU cache.
 
Method Summary
 void clear()
          Clears the cache.
 V get(K key)
          Retrieves an entry from the cache.
The retrieved entry is move to the head of the list as it is the most recently used.
 java.util.Collection<java.util.Map.Entry<K,V>> getAll()
          Returns a Collection that contains a copy of all cache entries.
 int getMaximumSize()
           
 java.util.Set<K> keySet()
           
 void put(K key, V value)
          Adds an entry to this cache.
 void remove(K key)
          Remove an entry from the cache.
 int usedEntries()
          Returns the number of used entries in the cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LRUCache2

public LRUCache2(int cacheSize)
Creates a new LRU cache.

Parameters:
cacheSize - The maximum number of entries that will be kept in this cache.
Method Detail

get

public V get(K key)
Retrieves an entry from the cache.
The retrieved entry is move to the head of the list as it is the most recently used.

Parameters:
key -
Returns:
The value associated to this key

put

public void put(K key,
                V value)
Adds an entry to this cache. If the cache is full, the LRU (least recently used) entry is dropped.

Parameters:
key -
value -

remove

public void remove(K key)
Remove an entry from the cache.

Parameters:
key -

clear

public void clear()
Clears the cache.


usedEntries

public int usedEntries()
Returns the number of used entries in the cache.

Returns:
the number of entries currently in the cache.

getAll

public java.util.Collection<java.util.Map.Entry<K,V>> getAll()
Returns a Collection that contains a copy of all cache entries.

Returns:
a Collection with a copy of the cache content.

keySet

public java.util.Set<K> keySet()

getMaximumSize

public int getMaximumSize()


Copyright © 2008-2011 Simon Ritchie. All Rights Reserved.