Top Description Fields Constructors Methods
org.codehaus.groovy.runtime.memoize

pack-priv final Class LRUProtectionStorage

extends LinkedHashMap<Object, Object>
implements ProtectionStorage
Class Inheritance
All Implemented Interfaces
org.codehaus.groovy.runtime.memoize.ProtectionStorage
Imports
java.util.LinkedHashMap, .Map

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.

Field Summary

Modifier and TypeField and Description
private final int
private static final long

Constructor Summary

AccessConstructor and Description
public
LRUProtectionStorage(final int maxSize)

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

The cloned instance
clone
()

Overrides java.util.HashMap.clone.

Performs a shallow clone
public synchronized Object
get(final Object
the key whose associated value is to be returned
key
)

Overrides java.util.LinkedHashMap.get.

Implements java.util.Map.get.

Makes sure the retrieved object is moved to the head of the LRU list
protected synchronized boolean
removeEldestEntry(final Map.Entry<Object, Object>
The least recently inserted entry in the map, or if this is an access-ordered map, the least recently accessed entry. This is the entry that will be removed if this method returns true. If the map was empty prior to the put or putAll invocation resulting in this invocation, this will be the entry that was just inserted; in other words, if the map contains a single entry, the eldest entry is also the newest.
eldest
)

Overrides java.util.LinkedHashMap.removeEldestEntry.

The eldest entry should be removed when we reached the maximum cache size
public synchronized void
touch(final Object
The key of the element to renew
key
,
final Object
A value to newly associate with the key
value
)

Implements org.codehaus.groovy.runtime.memoize.ProtectionStorage.touch.

The touch method can be used to renew an element and move it to the from of the LRU queue.
Inherited from java.util.LinkedHashMap:
clearcontainsValueentrySetforEachgetOrDefaultkeySetnewLinkedHashMapputFirstputLastreplaceAllreversedsequencedEntrySetsequencedKeySetsequencedValuesvalues

Field Detail

maxSizeback to summary
private final int maxSize
serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.util.LinkedHashMap.serialVersionUID.

Constructor Detail

LRUProtectionStorageback to summary
public LRUProtectionStorage(final int maxSize)

Method Detail

cloneback to summary
public Object clone()

Overrides java.util.HashMap.clone.

Performs a shallow clone

Returns:Object

The cloned instance

Annotations
@Override
getback to summary
public synchronized Object get(final Object key)

Overrides java.util.LinkedHashMap.get.

Implements java.util.Map.get.

Makes sure the retrieved object is moved to the head of the LRU list

Parameters
key:Object

Doc from java.util.Map.get.

the key whose associated value is to be returned

Returns:Object

Doc from java.util.Map.get.

the value to which the specified key is mapped, or null if this map contains no mapping for the key

Annotations
@Override
removeEldestEntryback to summary
protected synchronized boolean removeEldestEntry(final Map.Entry<Object, Object> eldest)

Overrides java.util.LinkedHashMap.removeEldestEntry.

The eldest entry should be removed when we reached the maximum cache size

Parameters
eldest:Map.Entry<Object, Object>

Doc from java.util.LinkedHashMap.removeEldestEntry.

The least recently inserted entry in the map, or if this is an access-ordered map, the least recently accessed entry. This is the entry that will be removed if this method returns true. If the map was empty prior to the put or putAll invocation resulting in this invocation, this will be the entry that was just inserted; in other words, if the map contains a single entry, the eldest entry is also the newest.

Returns:boolean

Doc from java.util.LinkedHashMap.removeEldestEntry.

true if the eldest entry should be removed from the map; false if it should be retained.

Annotations
@Override
touchback to summary
public synchronized void touch(final Object key, final Object value)

Implements org.codehaus.groovy.runtime.memoize.ProtectionStorage.touch.

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

Parameters
key:Object

The key of the element to renew

value:Object

A value to newly associate with the key