public class LruMemoryStore extends AbstractStore
LinkedHashMap
as its backing map. It uses the LinkedHashMap
LRU
feature. LRU for this implementation means least recently accessed.Modifier and Type | Class and Description |
---|---|
class |
LruMemoryStore.SpoolingLinkedHashMap
An extension of LinkedHashMap which overrides
LruMemoryStore.SpoolingLinkedHashMap.removeEldestEntry(java.util.Map.Entry)
to persist cache entries to the auxiliary cache before they are removed. |
Modifier and Type | Field and Description |
---|---|
protected Ehcache |
cache
The cache this store is associated with.
|
protected Store |
diskStore
The DiskStore associated with this MemoryStore.
|
protected Map |
map
Map where items are stored by key.
|
protected long |
maximumSize
The maximum size of the store (0 == no limit)
|
protected Status |
status
status.
|
attributeExtractors
CLUSTER_COHERENT, NODE_COHERENT
Constructor and Description |
---|
LruMemoryStore(Ehcache cache,
Store diskStore)
Constructor for the LruMemoryStore object
The backing
LinkedHashMap is created with LRU by access order. |
Modifier and Type | Method and Description |
---|---|
boolean |
bufferFull()
Memory stores are never backed up and always return false
|
protected void |
clear()
Clears any data structures and places it back to its state when it was first created.
|
boolean |
containsKey(Object key)
An unsynchronized check to see if a key is in the Store.
|
boolean |
containsKeyInMemory(Object key)
A check to see if a key is in the Store and is currently held in memory.
|
boolean |
containsKeyOffHeap(Object key)
A check to see if a key is in the Store and is currently held off-heap.
|
boolean |
containsKeyOnDisk(Object key)
A check to see if a key is in the Store and is currently held on disk.
|
void |
dispose()
Prepares for shutdown.
|
protected void |
doPut(Element element)
Allow specialised actions over adding the element to the map.
|
protected void |
evict(Element element)
Evict the
Element . |
void |
expireElements()
Expire all elsments.
|
void |
flush()
Flush to disk only if the cache is diskPersistent.
|
Element |
get(Object key)
Gets an item from the cache.
|
Policy |
getEvictionPolicy() |
Policy |
getInMemoryEvictionPolicy() |
int |
getInMemorySize()
Returns the current local in-memory store size
|
long |
getInMemorySizeInBytes()
Gets the size of the in-memory portion of the store, in bytes.
|
Object |
getInternalContext()
This should not be used, and will generally return null
|
List |
getKeys()
Gets an Array of the keys for all elements in the memory cache.
|
Object |
getMBean()
Optional implementation specific MBean exposed by the store.
|
int |
getOffHeapSize()
Returns the current local off-heap store size
|
long |
getOffHeapSizeInBytes()
Gets the size of the off-heap portion of the store, in bytes.
|
int |
getOnDiskSize()
Returns the current local on-disk store size
|
long |
getOnDiskSizeInBytes()
Gets the size of the on-disk portion of the store, in bytes.
|
Element |
getQuiet(Object key)
Gets an item from the cache, without updating statistics.
|
int |
getSize()
Returns the current cache size.
|
long |
getSizeInBytes()
Measures the size of the memory store by using the sizeof engine.
|
Status |
getStatus()
Gets the status of the MemoryStore.
|
int |
getTerracottaClusteredSize()
Returns nothing since a disk store isn't clustered
|
protected boolean |
isFull()
An algorithm to tell if the MemoryStore is at or beyond its carrying capacity.
|
boolean |
isPinned(Object key)
Check if the key is pinned
|
protected void |
notifyExpiry(Element element)
Before eviction elements are checked.
|
boolean |
put(Element element)
Puts an item in the cache.
|
Element |
putIfAbsent(Element element)
Unsupported in LruMemoryStore
|
boolean |
putWithWriter(Element element,
CacheWriterManager writerManager)
Puts an item into the store and the cache writer manager in an atomic operation
|
Element |
remove(Object key)
Removes an Element from the store.
|
void |
removeAll()
Remove all of the elements from the store.
|
Element |
removeElement(Element element,
ElementValueComparator comparator)
Unsupported in LruMemoryStore
|
Element |
removeWithWriter(Object key,
CacheWriterManager writerManager)
Removes an item from the store and the cache writer manager in an atomic operation.
|
Element |
replace(Element element)
Unsupported in LruMemoryStore
|
boolean |
replace(Element old,
Element element,
ElementValueComparator comparator)
Unsupported in LruMemoryStore
|
void |
setEvictionPolicy(Policy policy)
Sets the eviction policy strategy.
|
void |
setInMemoryEvictionPolicy(Policy policy)
Sets the eviction policy strategy.
|
void |
setPinned(Object key,
boolean pinned)
Mark the key as pinned or not
|
protected void |
spoolAllToDisk()
Spools all elements to disk, in preparation for shutdown.
|
protected void |
spoolToDisk(Element element)
Puts the element in the DiskStore.
|
void |
unpinAll()
unpin all pinned keys
|
addStoreListener, executeQuery, getAll, getAllQuiet, getEventListenerList, getSearchAttribute, hasAbortedSizeOf, isCacheCoherent, isClusterCoherent, isNodeCoherent, putAll, recalculateSize, removeAll, removeStoreListener, setAttributeExtractors, setNodeCoherent, waitUntilClusterCoherent
protected Ehcache cache
protected Map map
protected final Store diskStore
protected Status status
protected long maximumSize
public LruMemoryStore(Ehcache cache, Store diskStore)
LinkedHashMap
is created with LRU by access order.public void unpinAll()
public boolean isPinned(Object key)
key
- the key to be checkedtrue
if the element is pinnedpublic void setPinned(Object key, boolean pinned)
key
- the key to be pinned or notpinned
- true if the key should be pinned, false otherwisepublic final boolean put(Element element) throws CacheException
LruMemoryStore.SpoolingLinkedHashMap.removeEldestEntry(java.util.Map.Entry)
being called.element
- the element to addCacheException
public final boolean putWithWriter(Element element, CacheWriterManager writerManager) throws CacheException
CacheException
protected void doPut(Element element) throws CacheException
element
- CacheException
public final Element get(Object key)
Element
is updated.key
- the cache keypublic final Element getQuiet(Object key)
key
- the cache keypublic final Element remove(Object key)
key
- the key of the Element, usually a Stringpublic final Element removeWithWriter(Object key, CacheWriterManager writerManager) throws CacheException
CacheException
public final void removeAll() throws CacheException
CacheException
protected final void clear()
public final void dispose()
public final void flush()
protected final void spoolAllToDisk()
protected void spoolToDisk(Element element)
element
- The Elementpublic final Status getStatus()
public final List getKeys()
public final int getSize()
public final int getTerracottaClusteredSize()
public final boolean containsKey(Object key)
key
- The Element keypublic final long getSizeInBytes() throws CacheException
CacheException
protected final void evict(Element element) throws CacheException
Element
.
Evict means that the Element
is:
Element
is spooled to the DiskStore
Element
is removed.
element
- the Element
to be evicted.CacheException
protected final void notifyExpiry(Element element)
element
- protected final boolean isFull()
public void expireElements()
public boolean bufferFull()
public Object getMBean()
public Policy getEvictionPolicy()
setEvictionPolicy(Policy)
public void setEvictionPolicy(Policy policy)
policy
- the new policypublic Object getInternalContext()
public boolean containsKeyInMemory(Object key)
key
- The Element keypublic boolean containsKeyOffHeap(Object key)
key
- The Element keypublic boolean containsKeyOnDisk(Object key)
key
- The Element keypublic Policy getInMemoryEvictionPolicy()
Store.setInMemoryEvictionPolicy(Policy)
public int getInMemorySize()
public long getInMemorySizeInBytes()
public int getOffHeapSize()
public long getOffHeapSizeInBytes()
public int getOnDiskSize()
public long getOnDiskSizeInBytes()
public void setInMemoryEvictionPolicy(Policy policy)
policy
- the new policypublic Element putIfAbsent(Element element) throws NullPointerException
element
- element to be addedNullPointerException
- if the element is null, or has a null keypublic Element removeElement(Element element, ElementValueComparator comparator) throws NullPointerException
element
- Element to be removedcomparator
- ElementValueComparator to use to compare elementsNullPointerException
- if the element is null, or has a null keypublic boolean replace(Element old, Element element, ElementValueComparator comparator) throws NullPointerException, IllegalArgumentException
old
- Element to be test againstelement
- Element to be cachedcomparator
- ElementValueComparator to use to compare elementsNullPointerException
- if the either Element is null or has a null keyIllegalArgumentException
- if the two Element keys are non-null but not equalpublic Element replace(Element element) throws NullPointerException
element
- Element to be cachedNullPointerException
- if the Element is null or has a null keyCopyright © 2003-2013 Terracotta, Inc.. All Rights Reserved.