Top Description Inners Fields Constructors Methods
net.sf.ehcache.store

public Class LruMemoryStore

extends AbstractStore
Class Inheritance
Imports
net.sf.ehcache.CacheEntry, .CacheException, .Ehcache, .Element, .Status, .CacheOperationOutcomes.EvictionOutcome, net.sf.ehcache.config.CacheConfiguration, .PinningConfiguration, .SizeOfPolicyConfiguration, net.sf.ehcache.pool.Size, .SizeOfEngine, .SizeOfEngineLoader, net.sf.ehcache.writer.CacheWriterManager, org.slf4j.Logger, .LoggerFactory, java.util.ArrayList, .Iterator, .List, .Map, net.sf.ehcache.statistics.StatisticBuilder, net.sf.ehcache.store.StoreOperationOutcomes.GetOutcome, .StoreOperationOutcomes.PutOutcome, .StoreOperationOutcomes.RemoveOutcome, org.terracotta.statistics.Statistic, org.terracotta.statistics.observer.OperationObserver

An implementation of a LruMemoryStore.

This uses java.util.LinkedHashMap as its backing map. It uses the java.util.LinkedHashMap LRU feature. LRU for this implementation means least recently accessed.

Author
Greg Luck
Version
$Id$

Nested and Inner Type Summary

Modifier and TypeClass and Description
public class
LruMemoryStore.SpoolingLinkedHashMap

An extension of LinkedHashMap which overrides removeEldestEntry to persist cache entries to the auxiliary cache before they are removed.

Field Summary

Modifier and TypeField and Description
protected Ehcache
cache

The cache this store is associated with.

private final boolean
private final CopyStrategyHandler
protected final Store
diskStore

The DiskStore associated with this MemoryStore.

private final boolean
private final OperationObserver<CacheOperationOutcomes.EvictionOutcome>
private final OperationObserver<StoreOperationOutcomes.GetOutcome>
private static final Logger
protected Map<K, V>
map

Map where items are stored by key.

protected long
maximumSize

The maximum size of the store (0 == no limit)

private final OperationObserver<StoreOperationOutcomes.PutOutcome>
private final OperationObserver<StoreOperationOutcomes.RemoveOutcome>
protected Status
status

status.

Inherited from net.sf.ehcache.store.AbstractStore:
attributeExtractorssearchManager

Constructor Summary

AccessConstructor and Description
public
LruMemoryStore(Ehcache cache, Store diskStore)

Constructor for the LruMemoryStore object The backing java.util.LinkedHashMap is created with LRU by access order.

Method Summary

Modifier and TypeMethod and Description
public boolean
bufferFull()

Implements net.sf.ehcache.store.Store.bufferFull.

Memory stores are never backed up and always return false
protected final void
clear()

Clears any data structures and places it back to its state when it was first created.

public final boolean

Returns:

true if found. If this method return false, it means that an Element with the given key is definitely not in the MemoryStore. If it returns true, there is an Element there. An attempt to get it may return null if the Element has expired.
containsKey
(Object
The Element key
key
)

Implements net.sf.ehcache.store.Store.containsKey.

An unsynchronized check to see if a key is in the Store.
public boolean
containsKeyInMemory(Object
The Element key
key
)

Implements net.sf.ehcache.store.Store.containsKeyInMemory.

A check to see if a key is in the Store and is currently held in memory.
public boolean
containsKeyOffHeap(Object
The Element key
key
)

Implements net.sf.ehcache.store.Store.containsKeyOffHeap.

A check to see if a key is in the Store and is currently held off-heap.
public boolean
containsKeyOnDisk(Object
The Element key
key
)

Implements net.sf.ehcache.store.Store.containsKeyOnDisk.

A check to see if a key is in the Store and is currently held on disk.
private boolean
public final synchronized void
dispose()

Implements net.sf.ehcache.store.Store.dispose.

Prepares for shutdown.
protected void
doPut(Element element)

Allow specialised actions over adding the element to the map.

protected final void
evict(Element
the Element to be evicted.
element
)

Evict the Element.

public void
public final void
flush()

Implements net.sf.ehcache.store.Store.flush.

Flush to disk only if the cache is diskPersistent.
public final synchronized Element

Returns:

the element, or null if there was no match for the key
get
(Object
the cache key
key
)

Implements net.sf.ehcache.store.Store.get.

Gets an item from the cache.
pack-priv Map<K, V>
getBackingMap()

Package local access to the map for testing

public Policy

Returns:

the current eviction policy. This may not be the configured policy, if it has been dynamically set.
getEvictionPolicy
()

public Policy
public int
getInMemorySize()

Implements net.sf.ehcache.store.Store.getInMemorySize.

Returns the current local in-memory store size
public long
getInMemorySizeInBytes()

Implements net.sf.ehcache.store.Store.getInMemorySizeInBytes.

Gets the size of the in-memory portion of the store, in bytes.
public Object
getInternalContext()

Implements net.sf.ehcache.store.Store.getInternalContext.

This should not be used, and will generally return null
public final synchronized List<E>

Returns:

An Object[]
getKeys
()

Implements net.sf.ehcache.store.Store.getKeys.

Gets an Array of the keys for all elements in the memory cache.
public Object
getMBean()

Implements net.sf.ehcache.store.Store.getMBean.

Optional implementation specific MBean exposed by the store.
public int
getOffHeapSize()

Implements net.sf.ehcache.store.Store.getOffHeapSize.

Returns the current local off-heap store size
public long
getOffHeapSizeInBytes()

Implements net.sf.ehcache.store.Store.getOffHeapSizeInBytes.

Gets the size of the off-heap portion of the store, in bytes.
public int
getOnDiskSize()

Implements net.sf.ehcache.store.Store.getOnDiskSize.

Returns the current local on-disk store size
public long
getOnDiskSizeInBytes()

Implements net.sf.ehcache.store.Store.getOnDiskSizeInBytes.

Gets the size of the on-disk portion of the store, in bytes.
public final synchronized Element

Returns:

the element, or null if there was no match for the key
getQuiet
(Object
the cache key
key
)

Implements net.sf.ehcache.store.Store.getQuiet.

Gets an item from the cache, without updating statistics.
public final int

Returns:

The size value
getSize
()

Implements net.sf.ehcache.store.Store.getSize.

Returns the current cache size.
public final synchronized long

Returns:

the size, in bytes
getSizeInBytes
()

Measures the size of the memory store by using the sizeof engine.

public final Status
getStatus()

Implements net.sf.ehcache.store.Store.getStatus.

Gets the status of the MemoryStore.
public final int

Returns:

returns 0
getTerracottaClusteredSize
()

Implements net.sf.ehcache.store.Store.getTerracottaClusteredSize.

Returns nothing since a disk store isn't clustered
protected final boolean
isFull()

An algorithm to tell if the MemoryStore is at or beyond its carrying capacity.

protected final void
notifyExpiry(Element element)

Before eviction elements are checked.

public final boolean
put(Element
the element to add
element
)

Implements net.sf.ehcache.store.Store.put.

Puts an item in the cache.
public Element
putIfAbsent(Element
element to be added
element
)

Implements net.sf.ehcache.store.Store.putIfAbsent.

Unsupported in LruMemoryStore
private synchronized boolean
putInternal(Element element, CacheWriterManager writerManager)

public final boolean
putWithWriter(Element element, CacheWriterManager writerManager)

Implements net.sf.ehcache.store.Store.putWithWriter.

Puts an item into the store and the cache writer manager in an atomic operation
public final Element

Returns:

the Element if one was found, else null
remove
(Object
the key of the Element, usually a String
key
)

Implements net.sf.ehcache.store.Store.remove.

Removes an Element from the store.
public final synchronized void
removeAll()

Implements net.sf.ehcache.store.Store.removeAll.

Remove all of the elements from the store.
public Element
removeElement(Element
Element to be removed
element
,
ElementValueComparator
ElementValueComparator to use to compare elements
comparator
)

Implements net.sf.ehcache.store.Store.removeElement.

Unsupported in LruMemoryStore
private synchronized Element
public final Element
removeWithWriter(Object key, CacheWriterManager writerManager)

Implements net.sf.ehcache.store.Store.removeWithWriter.

Removes an item from the store and the cache writer manager in an atomic operation.
public boolean
replace(Element
Element to be test against
old
,
Element
Element to be cached
element
,
ElementValueComparator
ElementValueComparator to use to compare elements
comparator
)

Implements net.sf.ehcache.store.Store.replace.

Unsupported in LruMemoryStore
public Element
replace(Element
Element to be cached
element
)

Implements net.sf.ehcache.store.Store.replace.

Unsupported in LruMemoryStore
public void
setEvictionPolicy(Policy
the new policy
policy
)

Sets the eviction policy strategy.

public void
setInMemoryEvictionPolicy(Policy
the new policy
policy
)

Implements net.sf.ehcache.store.Store.setInMemoryEvictionPolicy.

Sets the eviction policy strategy.
protected final void
spoolAllToDisk()

Spools all elements to disk, in preparation for shutdown.

protected void
spoolToDisk(Element
The Element
element
)

Puts the element in the DiskStore.

Inherited from net.sf.ehcache.store.AbstractStore:
addStoreListenerexecuteQuerygetAllgetAllQuietgetEventListenerListgetSearchAttributegetSearchAttributeshasAbortedSizeOfisCacheCoherentisClusterCoherentisNodeCoherentputAllrecalculateSizeremoveAllremoveStoreListenersetAttributeExtractorssetNodeCoherentwaitUntilClusterCoherent

Field Detail

cacheback to summary
protected Ehcache cache

The cache this store is associated with.

cachePinnedback to summary
private final boolean cachePinned
copyStrategyHandlerback to summary
private final CopyStrategyHandler copyStrategyHandler
diskStoreback to summary
protected final Store diskStore

The DiskStore associated with this MemoryStore.

elementPinningEnabledback to summary
private final boolean elementPinningEnabled
evictionObserverback to summary
private final OperationObserver<CacheOperationOutcomes.EvictionOutcome> evictionObserver
getObserverback to summary
private final OperationObserver<StoreOperationOutcomes.GetOutcome> getObserver
LOGback to summary
private static final Logger LOG
mapback to summary
protected Map<K, V> map

Map where items are stored by key.

maximumSizeback to summary
protected long maximumSize

The maximum size of the store (0 == no limit)

putObserverback to summary
private final OperationObserver<StoreOperationOutcomes.PutOutcome> putObserver
removeObserverback to summary
private final OperationObserver<StoreOperationOutcomes.RemoveOutcome> removeObserver
statusback to summary
protected Status status

status.

Constructor Detail

LruMemoryStoreback to summary
public LruMemoryStore(Ehcache cache, Store diskStore)

Constructor for the LruMemoryStore object The backing java.util.LinkedHashMap is created with LRU by access order.

Method Detail

bufferFullback to summary
public boolean bufferFull()

Implements net.sf.ehcache.store.Store.bufferFull.

Memory stores are never backed up and always return false

Returns:boolean

Doc from net.sf.ehcache.store.Store.bufferFull.

true if the store write buffer is backed up.

clearback to summary
protected final void clear()

Clears any data structures and places it back to its state when it was first created.

containsKeyback to summary
public final boolean containsKey(Object key)

Implements net.sf.ehcache.store.Store.containsKey.

An unsynchronized check to see if a key is in the Store. No check is made to see if the Element is expired.

Parameters
key:Object

The Element key

Returns:boolean

true if found. If this method return false, it means that an Element with the given key is definitely not in the MemoryStore. If it returns true, there is an Element there. An attempt to get it may return null if the Element has expired.

containsKeyInMemoryback to summary
public boolean containsKeyInMemory(Object key)

Implements net.sf.ehcache.store.Store.containsKeyInMemory.

Doc from net.sf.ehcache.store.Store.containsKeyInMemory.

A check to see if a key is in the Store and is currently held in memory.

Parameters
key:Object

The Element key

Returns:boolean

true if found. No check is made to see if the Element is expired.

containsKeyOffHeapback to summary
public boolean containsKeyOffHeap(Object key)

Implements net.sf.ehcache.store.Store.containsKeyOffHeap.

Doc from net.sf.ehcache.store.Store.containsKeyOffHeap.

A check to see if a key is in the Store and is currently held off-heap.

Parameters
key:Object

The Element key

Returns:boolean

true if found. No check is made to see if the Element is expired.

containsKeyOnDiskback to summary
public boolean containsKeyOnDisk(Object key)

Implements net.sf.ehcache.store.Store.containsKeyOnDisk.

Doc from net.sf.ehcache.store.Store.containsKeyOnDisk.

A check to see if a key is in the Store and is currently held on disk.

Parameters
key:Object

The Element key

Returns:boolean

true if found. No check is made to see if the Element is expired.

determineCachePinnedback to summary
private boolean determineCachePinned(CacheConfiguration cacheConfiguration)
disposeback to summary
public final synchronized void dispose()

Implements net.sf.ehcache.store.Store.dispose.

Prepares for shutdown.

doPutback to summary
protected void doPut(Element element) throws CacheException

Allow specialised actions over adding the element to the map.

evictback to summary
protected final void evict(Element element) throws CacheException

Evict the Element.

Evict means that the Element is:

  • if, the store is diskPersistent, the Element is spooled to the DiskStore
  • if not, the Element is removed.
Parameters
element:Element

the Element to be evicted.

expireElementsback to summary
public void expireElements()

Implements net.sf.ehcache.store.Store.expireElements.

Expire all elsments.

This is a default implementation which does nothing. Expiry on demand is only implemented for disk stores.

flushback to summary
public final void flush()

Implements net.sf.ehcache.store.Store.flush.

Flush to disk only if the cache is diskPersistent.

getback to summary
public final synchronized Element get(Object key)

Implements net.sf.ehcache.store.Store.get.

Gets an item from the cache.

The last access time in net.sf.ehcache.Element is updated.

Parameters
key:Object

the cache key

Returns:Element

the element, or null if there was no match for the key

getBackingMapback to summary
pack-priv Map<K, V> getBackingMap()

Package local access to the map for testing

getEvictionPolicyback to summary
public Policy getEvictionPolicy()
Returns:Policy

the current eviction policy. This may not be the configured policy, if it has been dynamically set.

See Also
setEvictionPolicy(Policy)
getInMemoryEvictionPolicyback to summary
public Policy getInMemoryEvictionPolicy()

Implements net.sf.ehcache.store.Store.getInMemoryEvictionPolicy.

Returns:Policy

Doc from net.sf.ehcache.store.Store.getInMemoryEvictionPolicy.

the current eviction policy. This may not be the configured policy, if it has been dynamically set.

getInMemorySizeback to summary
public int getInMemorySize()

Implements net.sf.ehcache.store.Store.getInMemorySize.

Doc from net.sf.ehcache.store.Store.getInMemorySize.

Returns the current local in-memory store size

Returns:int

the count of the Elements in the Store and in-memory on the local machine

Annotations
@Statistic
name:size
tags:local-heap
getInMemorySizeInBytesback to summary
public long getInMemorySizeInBytes()

Implements net.sf.ehcache.store.Store.getInMemorySizeInBytes.

Doc from net.sf.ehcache.store.Store.getInMemorySizeInBytes.

Gets the size of the in-memory portion of the store, in bytes.

This method may be expensive to run, depending on implementation. Implementers may choose to return an approximate size.

Returns:long

the approximate in-memory size of the store in bytes

Annotations
@Statistic
name:size-in-bytes
tags:local-heap
getInternalContextback to summary
public Object getInternalContext()

Implements net.sf.ehcache.store.Store.getInternalContext.

Doc from net.sf.ehcache.store.Store.getInternalContext.

This should not be used, and will generally return null

Returns:Object

some internal context (probably null)

getKeysback to summary
public final synchronized List<E> getKeys()

Implements net.sf.ehcache.store.Store.getKeys.

Gets an Array of the keys for all elements in the memory cache.

Does not check for expired entries

Returns:List<E>

An Object[]

getMBeanback to summary
public Object getMBean()

Implements net.sf.ehcache.store.Store.getMBean.

Doc from net.sf.ehcache.store.Store.getMBean.

Optional implementation specific MBean exposed by the store.

Returns:Object

implementation specific management bean

getOffHeapSizeback to summary
public int getOffHeapSize()

Implements net.sf.ehcache.store.Store.getOffHeapSize.

Doc from net.sf.ehcache.store.Store.getOffHeapSize.

Returns the current local off-heap store size

Returns:int

the count of the Elements in the Store and off-heap on the local machine

getOffHeapSizeInBytesback to summary
public long getOffHeapSizeInBytes()

Implements net.sf.ehcache.store.Store.getOffHeapSizeInBytes.

Doc from net.sf.ehcache.store.Store.getOffHeapSizeInBytes.

Gets the size of the off-heap portion of the store, in bytes.

Returns:long

the approximate off-heap size of the store in bytes

getOnDiskSizeback to summary
public int getOnDiskSize()

Implements net.sf.ehcache.store.Store.getOnDiskSize.

Doc from net.sf.ehcache.store.Store.getOnDiskSize.

Returns the current local on-disk store size

Returns:int

the count of the Elements in the Store and on-disk on the local machine

getOnDiskSizeInBytesback to summary
public long getOnDiskSizeInBytes()

Implements net.sf.ehcache.store.Store.getOnDiskSizeInBytes.

Doc from net.sf.ehcache.store.Store.getOnDiskSizeInBytes.

Gets the size of the on-disk portion of the store, in bytes.

Returns:long

the on-disk size of the store in bytes

getQuietback to summary
public final synchronized Element getQuiet(Object key)

Implements net.sf.ehcache.store.Store.getQuiet.

Gets an item from the cache, without updating statistics.

Parameters
key:Object

the cache key

Returns:Element

the element, or null if there was no match for the key

getSizeback to summary
public final int getSize()

Implements net.sf.ehcache.store.Store.getSize.

Returns the current cache size.

Returns:int

The size value

getSizeInBytesback to summary
public final synchronized long getSizeInBytes() throws CacheException

Measures the size of the memory store by using the sizeof engine.

Warning

This method can be very expensive to run. Allow approximately 1 second per 1MB of entries. Running this method could create liveness problems because the object lock is held for a long period

Returns:long

the size, in bytes

getStatusback to summary
public final Status getStatus()

Implements net.sf.ehcache.store.Store.getStatus.

Gets the status of the MemoryStore.

getTerracottaClusteredSizeback to summary
public final int getTerracottaClusteredSize()

Implements net.sf.ehcache.store.Store.getTerracottaClusteredSize.

Returns nothing since a disk store isn't clustered

Returns:int

returns 0

isFullback to summary
protected final boolean isFull()

An algorithm to tell if the MemoryStore is at or beyond its carrying capacity.

notifyExpiryback to summary
protected final void notifyExpiry(Element element)

Before eviction elements are checked.

putback to summary
public final boolean put(Element element) throws CacheException

Implements net.sf.ehcache.store.Store.put.

Puts an item in the cache. Note that this automatically results in net.sf.ehcache.store.LruMemoryStore.SpoolingLinkedHashMap#removeEldestEntry being called.

Parameters
element:Element

the element to add

Returns:boolean

Doc from net.sf.ehcache.store.Store.put.

true if this is a new put for the key or element is null. Returns false if it was an update.

putIfAbsentback to summary
public Element putIfAbsent(Element element) throws NullPointerException

Implements net.sf.ehcache.store.Store.putIfAbsent.

Unsupported in LruMemoryStore

Parameters
element:Element

Doc from net.sf.ehcache.store.Store.putIfAbsent.

element to be added

Returns:Element

Doc from net.sf.ehcache.store.Store.putIfAbsent.

the element previously cached for this key, or null if none.

Exceptions
NullPointerException:

Doc from net.sf.ehcache.store.Store.putIfAbsent.

if the element is null, or has a null key

putInternalback to summary
private synchronized boolean putInternal(Element element, CacheWriterManager writerManager) throws CacheException
putWithWriterback to summary
public final boolean putWithWriter(Element element, CacheWriterManager writerManager) throws CacheException

Implements net.sf.ehcache.store.Store.putWithWriter.

Doc from net.sf.ehcache.store.Store.putWithWriter.

Puts an item into the store and the cache writer manager in an atomic operation

Returns:boolean

true if this is a new put for the key or element is null. Returns false if it was an update.

removeback to summary
public final Element remove(Object key)

Implements net.sf.ehcache.store.Store.remove.

Removes an Element from the store.

Parameters
key:Object

the key of the Element, usually a String

Returns:Element

the Element if one was found, else null

removeAllback to summary
public final synchronized void removeAll() throws CacheException

Implements net.sf.ehcache.store.Store.removeAll.

Remove all of the elements from the store.

removeElementback to summary
public Element removeElement(Element element, ElementValueComparator comparator) throws NullPointerException

Implements net.sf.ehcache.store.Store.removeElement.

Unsupported in LruMemoryStore

Parameters
element:Element

Doc from net.sf.ehcache.store.Store.removeElement.

Element to be removed

comparator:ElementValueComparator

Doc from net.sf.ehcache.store.Store.removeElement.

ElementValueComparator to use to compare elements

Returns:Element

Doc from net.sf.ehcache.store.Store.removeElement.

the Element removed or null if no Element was removed

Exceptions
NullPointerException:

Doc from net.sf.ehcache.store.Store.removeElement.

if the element is null, or has a null key

removeInternalback to summary
private synchronized Element removeInternal(Object key, CacheWriterManager writerManager) throws CacheException
removeWithWriterback to summary
public final Element removeWithWriter(Object key, CacheWriterManager writerManager) throws CacheException

Implements net.sf.ehcache.store.Store.removeWithWriter.

Doc from net.sf.ehcache.store.Store.removeWithWriter.

Removes an item from the store and the cache writer manager in an atomic operation.

replaceback to summary
public boolean replace(Element old, Element element, ElementValueComparator comparator) throws NullPointerException, IllegalArgumentException

Implements net.sf.ehcache.store.Store.replace.

Unsupported in LruMemoryStore

Parameters
old:Element

Doc from net.sf.ehcache.store.Store.replace.

Element to be test against

element:Element

Doc from net.sf.ehcache.store.Store.replace.

Element to be cached

comparator:ElementValueComparator

Doc from net.sf.ehcache.store.Store.replace.

ElementValueComparator to use to compare elements

Returns:boolean

Doc from net.sf.ehcache.store.Store.replace.

true is the Element was replaced

Exceptions
NullPointerException:

Doc from net.sf.ehcache.store.Store.replace.

if the either Element is null or has a null key

IllegalArgumentException:

Doc from net.sf.ehcache.store.Store.replace.

if the two Element keys are non-null but not equal

replaceback to summary
public Element replace(Element element) throws NullPointerException

Implements net.sf.ehcache.store.Store.replace.

Unsupported in LruMemoryStore

Parameters
element:Element

Doc from net.sf.ehcache.store.Store.replace.

Element to be cached

Returns:Element

Doc from net.sf.ehcache.store.Store.replace.

the Element previously cached for this key, or null if no Element was cached

Exceptions
NullPointerException:

Doc from net.sf.ehcache.store.Store.replace.

if the Element is null or has a null key

setEvictionPolicyback to summary
public void setEvictionPolicy(Policy policy)

Sets the eviction policy strategy. The Store will use a policy at startup. The store may allow changing the eviction policy strategy dynamically. Otherwise implementations will throw an exception if this method is called.

Parameters
policy:Policy

the new policy

setInMemoryEvictionPolicyback to summary
public void setInMemoryEvictionPolicy(Policy policy)

Implements net.sf.ehcache.store.Store.setInMemoryEvictionPolicy.

Doc from net.sf.ehcache.store.Store.setInMemoryEvictionPolicy.

Sets the eviction policy strategy. The Store will use a policy at startup. The store may allow changing the eviction policy strategy dynamically. Otherwise implementations will throw an exception if this method is called.

Parameters
policy:Policy

the new policy

spoolAllToDiskback to summary
protected final void spoolAllToDisk()

Spools all elements to disk, in preparation for shutdown.

This revised implementation is a little slower but avoids using increased memory during the method.

spoolToDiskback to summary
protected void spoolToDisk(Element element)

Puts the element in the DiskStore. Should only be called if isOverflowToDisk is true

Relies on being called from a synchronized method

Parameters
element:Element

The Element

net.sf.ehcache.store back to summary

public final Class LruMemoryStore.SpoolingLinkedHashMap

extends LinkedHashMap
Class Inheritance

An extension of LinkedHashMap which overrides removeEldestEntry to persist cache entries to the auxiliary cache before they are removed.

This implementation also provides LRU by access order.

Field Summary

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

Constructor Summary

AccessConstructor and Description
public
SpoolingLinkedHashMap()

Default constructor.

Method Summary

Modifier and TypeMethod and Description
public Object
put(Object
key with which the specified value is to be associated
key
,
Object
value to be associated with the specified key
value
)

Overrides java.util.HashMap.put.

Implements java.util.Map.put.

Associates the specified value with the specified key in this map (optional operation).
protected final boolean

Returns:

true if the eldest entry should be removed from the map; false if it should be retained.
removeEldestEntry
(Map.Entry<K, V>
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 it 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.

Returns true if this map should remove its eldest entry.
private boolean

Returns:

true if the LRU element should be removed
removeLeastRecentlyUsedElement
(Element element)

Relies on being called from a synchronized method

Inherited from java.util.LinkedHashMap:
clearcontainsValueentrySetforEachgetgetOrDefaultkeySetnewLinkedHashMapputFirstputLastreplaceAllreversedsequencedEntrySetsequencedKeySetsequencedValuesvalues

Field Detail

GROWTH_FACTORback to summary
private static final float GROWTH_FACTOR
INITIAL_CAPACITYback to summary
private static final int INITIAL_CAPACITY

Constructor Detail

SpoolingLinkedHashMapback to summary
public SpoolingLinkedHashMap()

Default constructor. Will create an initial capacity of 100, a loading of .75 and LRU by access order.

Method Detail

putback to summary
public Object put(Object key, Object value)

Overrides java.util.HashMap.put.

Implements java.util.Map.put.

Doc from java.util.Map.put.

Associates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for the key, the old value is replaced by the specified value. (A map m is said to contain a mapping for a key k if and only if m.containsKey(k) would return true.)

Parameters
key:Object

key with which the specified value is to be associated

value:Object

value to be associated with the specified key

Returns:Object

the previous value associated with key, or null if there was no mapping for key. (A null return can also indicate that the map previously associated null with key, if the implementation supports null values.)

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

Overrides java.util.LinkedHashMap.removeEldestEntry.

Returns true if this map should remove its eldest entry. This method is invoked by put and putAll after inserting a new entry into the map. It provides the implementer with the opportunity to remove the eldest entry each time a new one is added. This is useful if the map represents a cache: it allows the map to reduce memory consumption by deleting stale entries.

Will return true if:

  1. the element has expired
  2. the cache size is greater than the in-memory actual. In this case we spool to disk before returning.
Parameters
eldest:Map.Entry<K, V>

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 it 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

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

Annotations
@Override
removeLeastRecentlyUsedElementback to summary
private boolean removeLeastRecentlyUsedElement(Element element) throws CacheException

Relies on being called from a synchronized method

Returns:boolean

true if the LRU element should be removed