|
ehcache | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.ehcache.store.AbstractStore
net.sf.ehcache.store.MemoryStore
public class MemoryStore
A Store implementation suitable for fast, concurrent in memory stores. The policy is determined by that configured in the cache.
Nested Class Summary | |
---|---|
protected static interface |
MemoryStore.BackingFactory
Factory interface to create a MemoryStore backing. |
Field Summary |
---|
Fields inherited from class net.sf.ehcache.store.AbstractStore |
---|
attributeExtractors |
Fields inherited from interface net.sf.ehcache.store.Store |
---|
CLUSTER_COHERENT, NODE_COHERENT |
Constructor Summary | |
---|---|
protected |
MemoryStore(Ehcache cache,
Pool pool,
boolean notify,
MemoryStore.BackingFactory factory)
Constructs things that all MemoryStores have in common. |
Method Summary | |
---|---|
boolean |
bufferFull()
Memory stores are never backed up and always return false |
boolean |
canPutWithoutEvicting(Element element)
Check if adding an element won't provoke an eviction. |
boolean |
containsKey(Object key)
A 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. |
static MemoryStore |
create(Ehcache cache,
Pool pool)
A factory method to create a MemoryStore. |
void |
deregistered(CacheConfiguration config)
Indicates that this listener was removed from the given configuration |
void |
diskCapacityChanged(int oldCapacity,
int newCapacity)
Indicates a change in the configurations disk store capacity |
void |
dispose()
Prepares for shutdown. |
Collection<Element> |
elementSet()
Get a collection of the elements in this store |
protected boolean |
evict(Element element)
Evicts the element from the store |
boolean |
evictFromOnDisk(int count,
long size)
Perform eviction to release on-disk resources |
boolean |
evictFromOnHeap(int count,
long size)
Perform eviction to release on-heap resources |
protected Element |
expireElement(Object key)
Evicts the element for the given key, if it exists and is expired |
void |
expireElements()
Expire all elements. |
void |
fill(Element element)
Add this element to the cache if the key is already present or the add can succeed without resorting to eviction. |
void |
flush()
Flush to disk only if the cache is diskPersistent. |
Element |
get(Object key)
Gets an item from the cache. |
long |
getApproximateDiskByteSize()
Return the approximate disk size in bytes |
long |
getApproximateDiskCountSize()
Return the approximate disk size |
float |
getApproximateDiskHitRate()
Return the approximate disk hit rate |
float |
getApproximateDiskMissRate()
Return the approximate disk miss rate |
long |
getApproximateHeapByteSize()
Return the approximate heap size in bytes |
long |
getApproximateHeapCountSize()
Return the approximate heap size |
float |
getApproximateHeapHitRate()
Return the approximate heap hit rate |
float |
getApproximateHeapMissRate()
Return the approximate heap miss rate |
protected static int |
getInitialCapacityForLoadFactor(int maximumSizeGoal,
float loadFactor)
Calculates the initialCapacity for a desired maximumSize goal and loadFactor. |
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. |
Set |
getPresentPinnedKeys()
Returns all the keys that are pinned, for which there is a mapping present |
Element |
getQuiet(Object key)
Gets an item from the cache, without updating statistics. |
int |
getSize()
Returns the current store size. |
Status |
getStatus()
Gets the status of the MemoryStore. |
int |
getTerracottaClusteredSize()
Returns nothing since a disk store isn't clustered |
boolean |
hasAbortedSizeOf()
Checks if the cache may contain elements for which the SizeOf engine gave up and only partially calculated the size. |
boolean |
isFull()
An algorithm to tell if the MemoryStore is at or beyond its carrying capacity. |
boolean |
isPersistent()
Is this store persistent (data survives a JVM restart) |
boolean |
isPinned(Object key)
Check if the key is pinned |
boolean |
isTierPinned()
Is this TierableStore pinned ? |
protected Set<?> |
keySet()
Returns the keySet for this store |
void |
loggingChanged(boolean oldValue,
boolean newValue)
Indicates a change in the configuration for enable/disable logging |
void |
maxBytesLocalDiskChanged(long oldValue,
long newValue)
Indicates a change in the configuration for maxBytesLocalDisk setting |
void |
maxBytesLocalHeapChanged(long oldValue,
long newValue)
Indicates a change in the configuration for maxBytesLocalHeap setting |
void |
memoryCapacityChanged(int oldCapacity,
int newCapacity)
Indicates a change in the configurations memory store capacity |
protected void |
notifyDirectEviction(Element element)
Called when an element is evicted even before it could be installed inside the store |
boolean |
put(Element element)
Puts an item in the store. |
Element |
putIfAbsent(Element element)
Put an element in the store if no element is currently mapped to the elements key. |
boolean |
putWithWriter(Element element,
CacheWriterManager writerManager)
Puts an item into the store and the cache writer manager in an atomic operation |
void |
recalculateSize(Object key)
Recalculate size of the element mapped to the key |
void |
registered(CacheConfiguration config)
Indicates that this listener was registered with the given configuration |
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)
Remove the Element mapped to the key for the supplied element if the value of the supplied Element is equal to the value of the cached Element. |
boolean |
removeIfNotPinned(Object key)
This method will only remove if the element or the store is not pinned and the key is present in the store |
void |
removeNoReturn(Object key)
Removes an item from the cache. |
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)
Replace the cached element only if an Element is currently cached for this key |
boolean |
replace(Element old,
Element element,
ElementValueComparator comparator)
Replace the cached element only if the value of the current Element is equal to the value of the supplied old Element. |
void |
setInMemoryEvictionPolicy(Policy policy)
Sets the eviction policy strategy. |
void |
setPinned(Object key,
boolean pinned)
Mark the key as pinned or not |
void |
timeToIdleChanged(long oldTti,
long newTti)
Indicates a change in the configurations time to idle |
void |
timeToLiveChanged(long oldTtl,
long newTtl)
Indicates a change in the configurations time to live |
void |
unpinAll()
unpin all pinned keys |
Methods inherited from class net.sf.ehcache.store.AbstractStore |
---|
addStoreListener, executeQuery, getAll, getAllQuiet, getEventListenerList, getSearchAttribute, isCacheCoherent, isClusterCoherent, isNodeCoherent, putAll, removeAll, removeStoreListener, setAttributeExtractors, setNodeCoherent, waitUntilClusterCoherent |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface net.sf.ehcache.store.Store |
---|
addStoreListener, executeQuery, getAll, getAllQuiet, getSearchAttribute, isCacheCoherent, isClusterCoherent, isNodeCoherent, putAll, removeAll, removeStoreListener, setAttributeExtractors, setNodeCoherent, waitUntilClusterCoherent |
Constructor Detail |
---|
protected MemoryStore(Ehcache cache, Pool pool, boolean notify, MemoryStore.BackingFactory factory)
cache
- the cachepool
- the pool tracking the on-heap usagenotify
- whether to notify the Cache's EventNotificationService on eviction and expiryMethod Detail |
---|
protected static int getInitialCapacityForLoadFactor(int maximumSizeGoal, float loadFactor)
maximumSizeGoal
- the desired maximum size goalloadFactor
- the load factor
public static MemoryStore create(Ehcache cache, Pool pool)
cache
- the cachepool
- the pool tracking the on-heap usage
public void unpinAll()
unpinAll
in interface Store
public void setPinned(Object key, boolean pinned)
setPinned
in interface Store
key
- the key to be pinned or notpinned
- true if the key should be pinned, false otherwisepublic boolean isPinned(Object key)
isPinned
in interface Store
key
- the key to be checked
true
if the element is pinnedpublic void fill(Element element)
fill
in interface TierableStore
element
- element to be addedpublic boolean removeIfNotPinned(Object key)
removeIfNotPinned
in interface TierableStore
key
- the key to the element
Store.remove(Object)
public boolean put(Element element) throws CacheException
put
in interface Store
element
- the element to add
CacheException
public boolean putWithWriter(Element element, CacheWriterManager writerManager) throws CacheException
putWithWriter
in interface Store
CacheException
public final Element get(Object key)
Element
is updated.
get
in interface Store
key
- the key of the Element
public final Element getQuiet(Object key)
getQuiet
in interface Store
key
- the cache key
public Element remove(Object key)
remove
in interface Store
key
- the key of the Element, usually a String
public void removeNoReturn(Object key)
removeNoReturn
in interface TierableStore
public boolean isTierPinned()
isTierPinned
in interface TierableStore
public Set getPresentPinnedKeys()
getPresentPinnedKeys
in interface TierableStore
public boolean isPersistent()
isPersistent
in interface TierableStore
public final Element removeWithWriter(Object key, CacheWriterManager writerManager) throws CacheException
removeWithWriter
in interface Store
CacheException
public final boolean bufferFull()
bufferFull
in interface Store
public void expireElements()
expireElements
in interface Store
protected Element expireElement(Object key)
key
- the key
public final void removeAll() throws CacheException
removeAll
in interface Store
CacheException
public void dispose()
dispose
in interface Store
public void flush()
flush
in interface Store
public final List<?> getKeys()
getKeys
in interface Store
protected Set<?> keySet()
public final int getSize()
getSize
in interface Store
public final int getTerracottaClusteredSize()
getTerracottaClusteredSize
in interface Store
public final boolean containsKey(Object key)
containsKey
in interface Store
key
- The Element key
protected void notifyDirectEviction(Element element)
element
- the evicted elementpublic final boolean isFull()
public final boolean canPutWithoutEvicting(Element element)
element
- the element
public Object getInternalContext()
getInternalContext
in interface Store
public final Status getStatus()
getStatus
in interface Store
public void timeToIdleChanged(long oldTti, long newTti)
timeToIdleChanged
in interface CacheConfigurationListener
oldTti
- previous time to idle valuenewTti
- new time to idle valuepublic void timeToLiveChanged(long oldTtl, long newTtl)
timeToLiveChanged
in interface CacheConfigurationListener
oldTtl
- previous time to live valuenewTtl
- new time to live valuepublic void diskCapacityChanged(int oldCapacity, int newCapacity)
diskCapacityChanged
in interface CacheConfigurationListener
oldCapacity
- previous capacitynewCapacity
- new capacitypublic void loggingChanged(boolean oldValue, boolean newValue)
loggingChanged
in interface CacheConfigurationListener
oldValue
- old value whether logging was enabled or notnewValue
- new value whether logging was enabled or notpublic void memoryCapacityChanged(int oldCapacity, int newCapacity)
memoryCapacityChanged
in interface CacheConfigurationListener
oldCapacity
- previous capacitynewCapacity
- new capacitypublic void registered(CacheConfiguration config)
registered
in interface CacheConfigurationListener
public void deregistered(CacheConfiguration config)
deregistered
in interface CacheConfigurationListener
public void maxBytesLocalHeapChanged(long oldValue, long newValue)
maxBytesLocalHeapChanged
in interface CacheConfigurationListener
oldValue
- old value in bytesnewValue
- new value in bytespublic void maxBytesLocalDiskChanged(long oldValue, long newValue)
maxBytesLocalDiskChanged
in interface CacheConfigurationListener
oldValue
- old value in bytesnewValue
- new value in bytespublic boolean containsKeyInMemory(Object key)
containsKeyInMemory
in interface Store
key
- The Element key
public boolean containsKeyOffHeap(Object key)
containsKeyOffHeap
in interface Store
key
- The Element key
public boolean containsKeyOnDisk(Object key)
containsKeyOnDisk
in interface Store
key
- The Element key
public Policy getInMemoryEvictionPolicy()
getInMemoryEvictionPolicy
in interface Store
Store.setInMemoryEvictionPolicy(Policy)
public int getInMemorySize()
getInMemorySize
in interface Store
public long getInMemorySizeInBytes()
getInMemorySizeInBytes
in interface Store
public int getOffHeapSize()
getOffHeapSize
in interface Store
public long getOffHeapSizeInBytes()
getOffHeapSizeInBytes
in interface Store
public int getOnDiskSize()
getOnDiskSize
in interface Store
public long getOnDiskSizeInBytes()
getOnDiskSizeInBytes
in interface Store
public boolean hasAbortedSizeOf()
hasAbortedSizeOf
in interface Store
hasAbortedSizeOf
in class AbstractStore
public void setInMemoryEvictionPolicy(Policy policy)
setInMemoryEvictionPolicy
in interface Store
policy
- the new policypublic Element putIfAbsent(Element element) throws NullPointerException
putIfAbsent
in interface Store
element
- element to be added
NullPointerException
- if the element is null, or has a null keyprotected boolean evict(Element element)
element
- the element to be evicted
public Element removeElement(Element element, ElementValueComparator comparator) throws NullPointerException
removeElement
in interface Store
element
- Element to be removedcomparator
- ElementValueComparator to use to compare elements
NullPointerException
- if the element is null, or has a null keypublic boolean replace(Element old, Element element, ElementValueComparator comparator) throws NullPointerException, IllegalArgumentException
replace
in interface Store
old
- Element to be test againstelement
- Element to be cachedcomparator
- ElementValueComparator to use to compare elements
NullPointerException
- if the either Element is null or has a null key
IllegalArgumentException
- if the two Element keys are non-null but not equalpublic Element replace(Element element) throws NullPointerException
replace
in interface Store
element
- Element to be cached
NullPointerException
- if the Element is null or has a null keypublic Object getMBean()
getMBean
in interface Store
public boolean evictFromOnHeap(int count, long size)
evictFromOnHeap
in interface PoolableStore
count
- the number of elements to evictsize
- the size in bytes to free (hint)
public boolean evictFromOnDisk(int count, long size)
evictFromOnDisk
in interface PoolableStore
count
- the number of elements to evictsize
- the size in bytes to free (hint)
public float getApproximateDiskHitRate()
getApproximateDiskHitRate
in interface PoolableStore
public float getApproximateDiskMissRate()
getApproximateDiskMissRate
in interface PoolableStore
public long getApproximateDiskCountSize()
getApproximateDiskCountSize
in interface PoolableStore
public long getApproximateDiskByteSize()
getApproximateDiskByteSize
in interface PoolableStore
public float getApproximateHeapHitRate()
getApproximateHeapHitRate
in interface PoolableStore
public float getApproximateHeapMissRate()
getApproximateHeapMissRate
in interface PoolableStore
public long getApproximateHeapCountSize()
getApproximateHeapCountSize
in interface PoolableStore
public long getApproximateHeapByteSize()
getApproximateHeapByteSize
in interface PoolableStore
public Collection<Element> elementSet()
public void recalculateSize(Object key)
AbstractStore
recalculateSize
in interface Store
recalculateSize
in class AbstractStore
key
- the key
|
ehcache | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |