org.codehaus.gpars

groovyx.gpars.memoize
[Java] Class LRUProtectionStorage

java.lang.Object
  java.util.AbstractMap
      java.util.HashMap
          java.util.LinkedHashMap
              groovyx.gpars.memoize.LRUProtectionStorage

public final class LRUProtectionStorage
extends java.util.LinkedHashMap

Protects stored resources from eviction from memory following the LRU (Last Recently Used) strategy. If the maximum size has been reached all newly added elements will cause the oldest element to be removed from the storage in order not to exceed the maximum capacity. The touch method can be used to renew an element and move it to the from the LRU queue.

Authors:
Vaclav Pech Date: Jun 22, 2010


Field Summary
private int maxSize

private static long serialVersionUID

 
Constructor Summary
LRUProtectionStorage(int maxSize)

 
Method Summary
java.lang.Object clone()

Performs a shallow clone

java.lang.Object get(java.lang.Object key)

protected boolean removeEldestEntry(java.lang.Object eldest)

void touch(java.lang.Object key, java.lang.Object value)

The touch method can be used to renew an element and move it to the from of the LRU queue.

 
Methods inherited from class java.util.LinkedHashMap
java.util.LinkedHashMap#get(java.lang.Object), java.util.LinkedHashMap#clear(), java.util.LinkedHashMap#containsValue(java.lang.Object), java.util.LinkedHashMap#put(java.lang.Object, java.lang.Object), java.util.LinkedHashMap#values(), java.util.LinkedHashMap#clone(), java.util.LinkedHashMap#isEmpty(), java.util.LinkedHashMap#entrySet(), java.util.LinkedHashMap#putAll(java.util.Map), java.util.LinkedHashMap#size(), java.util.LinkedHashMap#remove(java.lang.Object), java.util.LinkedHashMap#keySet(), java.util.LinkedHashMap#containsKey(java.lang.Object), java.util.LinkedHashMap#equals(java.lang.Object), java.util.LinkedHashMap#toString(), java.util.LinkedHashMap#hashCode(), java.util.LinkedHashMap#wait(long), java.util.LinkedHashMap#wait(), java.util.LinkedHashMap#wait(long, int), java.util.LinkedHashMap#getClass(), java.util.LinkedHashMap#notify(), java.util.LinkedHashMap#notifyAll()
 
Methods inherited from class java.util.HashMap
java.util.HashMap#get(java.lang.Object), java.util.HashMap#put(java.lang.Object, java.lang.Object), java.util.HashMap#values(), java.util.HashMap#clone(), java.util.HashMap#clear(), java.util.HashMap#isEmpty(), java.util.HashMap#entrySet(), java.util.HashMap#putAll(java.util.Map), java.util.HashMap#size(), java.util.HashMap#remove(java.lang.Object), java.util.HashMap#keySet(), java.util.HashMap#containsKey(java.lang.Object), java.util.HashMap#containsValue(java.lang.Object), java.util.HashMap#equals(java.lang.Object), java.util.HashMap#toString(), java.util.HashMap#hashCode(), java.util.HashMap#wait(long), java.util.HashMap#wait(), java.util.HashMap#wait(long, int), java.util.HashMap#getClass(), java.util.HashMap#notify(), java.util.HashMap#notifyAll()
 
Methods inherited from class java.util.AbstractMap
java.util.AbstractMap#get(java.lang.Object), java.util.AbstractMap#put(java.lang.Object, java.lang.Object), java.util.AbstractMap#equals(java.lang.Object), java.util.AbstractMap#toString(), java.util.AbstractMap#values(), java.util.AbstractMap#hashCode(), java.util.AbstractMap#clear(), java.util.AbstractMap#isEmpty(), java.util.AbstractMap#entrySet(), java.util.AbstractMap#putAll(java.util.Map), java.util.AbstractMap#size(), java.util.AbstractMap#remove(java.lang.Object), java.util.AbstractMap#keySet(), java.util.AbstractMap#containsKey(java.lang.Object), java.util.AbstractMap#containsValue(java.lang.Object), java.util.AbstractMap#wait(long), java.util.AbstractMap#wait(), java.util.AbstractMap#wait(long, int), java.util.AbstractMap#getClass(), java.util.AbstractMap#notify(), java.util.AbstractMap#notifyAll()
 
Methods inherited from class java.lang.Object
java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#wait(long, int), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Field Detail

maxSize

private final int maxSize


serialVersionUID

private static final long serialVersionUID


 
Constructor Detail

LRUProtectionStorage

public LRUProtectionStorage(int maxSize)


 
Method Detail

clone

@Override
public java.lang.Object clone()
Performs a shallow clone
Returns:
The cloned instance


get

@Override
public java.lang.Object get(java.lang.Object key)


removeEldestEntry

@Override
protected boolean removeEldestEntry(@SuppressWarnings("rawtypes") java.lang.Object eldest)


touch

@SuppressWarnings({"SynchronizedMethod"})
public void touch(java.lang.Object key, java.lang.Object value)
The touch method can be used to renew an element and move it to the from of the LRU queue.
Parameters:
key - The key of the element to renew
value - A value to newly associate with the key


 

Copyright © 2008–2010 Václav Pech. All Rights Reserved.