org.mmbase.cache.implementation
Class LRUCache<K,V>

java.lang.Object
  extended by org.mmbase.cache.implementation.LRUCache<K,V>
All Implemented Interfaces:
Map<K,V>, CacheImplementationInterface<K,V>

public class LRUCache<K,V>
extends Object
implements CacheImplementationInterface<K,V>

A cache implementation backed by a LinkedHashMap, in access-order mode, and restricted maximal size ('Least Recently Used' cache algorithm).

Since:
MMBase-1.8.6
Version:
$Id: LRUCache.java 41943 2010-04-16 17:18:19Z michiel $
Author:
Michiel Meeuwissen
See Also:
Cache

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
 int maxSize
           
 
Constructor Summary
LRUCache()
           
LRUCache(int size)
           
 
Method Summary
 void clear()
           
 void config(Map<String,String> map)
          Configure the implementation with the given configuration values
 boolean containsKey(Object key)
           
 boolean containsValue(Object value)
           
 Set<Map.Entry<K,V>> entrySet()
           
 V get(Object key)
           
 int getCount(K key)
          Returns the hit-count on a certain key (if implementable, -1 otherwise).
 Object getLock()
          The cache implementation must be somehow thread-safe.
 boolean isEmpty()
           
 Set<K> keySet()
           
 int maxSize()
          Gets the (maximal) size of the cache (if implementable)
 V put(K key, V value)
           
 void putAll(Map<? extends K,? extends V> map)
           
 V remove(Object key)
           
 void setMaxSize(int size)
          Change the maximum size of the table.
 int size()
           
 String toString()
          Returns size, maxSize.
 Collection<V> values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

maxSize

public int maxSize
Constructor Detail

LRUCache

public LRUCache()

LRUCache

public LRUCache(int size)
Method Detail

getCount

public int getCount(K key)
Description copied from interface: CacheImplementationInterface
Returns the hit-count on a certain key (if implementable, -1 otherwise).

Specified by:
getCount in interface CacheImplementationInterface<K,V>

setMaxSize

public void setMaxSize(int size)
Change the maximum size of the table. This may result in removal of entries in the table.

Specified by:
setMaxSize in interface CacheImplementationInterface<K,V>
Parameters:
size - the new desired size

maxSize

public final int maxSize()
Description copied from interface: CacheImplementationInterface
Gets the (maximal) size of the cache (if implementable)

Specified by:
maxSize in interface CacheImplementationInterface<K,V>

toString

public String toString()
Returns size, maxSize.

Overrides:
toString in class Object

config

public void config(Map<String,String> map)
Description copied from interface: CacheImplementationInterface
Configure the implementation with the given configuration values

Specified by:
config in interface CacheImplementationInterface<K,V>

getLock

public Object getLock()
Description copied from interface: CacheImplementationInterface
The cache implementation must be somehow thread-safe. This method should return the object on which to synchronize, e.g. when looping over entrySet.

Specified by:
getLock in interface CacheImplementationInterface<K,V>

size

public int size()
Specified by:
size in interface Map<K,V>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Map<K,V>

containsKey

public boolean containsKey(Object key)
Specified by:
containsKey in interface Map<K,V>

containsValue

public boolean containsValue(Object value)
Specified by:
containsValue in interface Map<K,V>

get

public V get(Object key)
Specified by:
get in interface Map<K,V>

put

public V put(K key,
             V value)
Specified by:
put in interface Map<K,V>

remove

public V remove(Object key)
Specified by:
remove in interface Map<K,V>

putAll

public void putAll(Map<? extends K,? extends V> map)
Specified by:
putAll in interface Map<K,V>

clear

public void clear()
Specified by:
clear in interface Map<K,V>

keySet

public Set<K> keySet()
Specified by:
keySet in interface Map<K,V>

entrySet

public Set<Map.Entry<K,V>> entrySet()
Specified by:
entrySet in interface Map<K,V>

values

public Collection<V> values()
Specified by:
values in interface Map<K,V>


MMBase 2.0-SNAPSHOT - null