|
ehcache | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.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 | |
---|---|
protected org.terracotta.statistics.observer.OperationObserver<CacheOperationOutcomes.EvictionOutcome> |
evictionObserver
Eviction outcome observer |
Fields inherited from class net.sf.ehcache.store.AbstractStore |
---|
attributeExtractors, searchManager |
Fields inherited from interface net.sf.ehcache.store.Store |
---|
CLUSTER_COHERENT, NODE_COHERENT |
Constructor Summary | |
---|---|
protected |
MemoryStore(Ehcache cache,
Pool pool,
MemoryStore.BackingFactory factory,
SearchManager searchManager)
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 Store |
create(Ehcache cache,
Pool pool)
A factory method to create a MemoryStore. |
protected static net.sf.ehcache.store.BruteForceSource |
createBruteForceSource(MemoryStore memoryStore,
CacheConfiguration cacheConfiguration)
Factory method to wrap the MemoryStore into a BruteForceSource, accounting for transactional and copy configuration |
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 |
protected Element |
expireElement(Object key)
Evicts the element for the given key, if it exists and is expired |
void |
expireElements()
Expire all elements. |
void |
flush()
Flush to disk only if the cache is diskPersistent. |
Element |
get(Object key)
Gets an item from the cache. |
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. |
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. |
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 |
maxEntriesInCacheChanged(long oldValue,
long newValue)
Indicates a change in the configuration for maxEntriesInCache 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. |
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 |
setAttributeExtractors(Map<String,AttributeExtractor> extractors)
Inform this store of the configured attribute extractors. |
void |
setInMemoryEvictionPolicy(Policy policy)
Sets the eviction policy strategy. |
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 |
Methods inherited from class net.sf.ehcache.store.AbstractStore |
---|
addStoreListener, executeQuery, getAll, getAllQuiet, getEventListenerList, getSearchAttribute, getSearchAttributes, isCacheCoherent, isClusterCoherent, isNodeCoherent, putAll, removeAll, removeStoreListener, 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, getSearchAttributes, isCacheCoherent, isClusterCoherent, isNodeCoherent, putAll, removeAll, removeStoreListener, setNodeCoherent, waitUntilClusterCoherent |
Field Detail |
---|
protected final org.terracotta.statistics.observer.OperationObserver<CacheOperationOutcomes.EvictionOutcome> evictionObserver
Constructor Detail |
---|
protected MemoryStore(Ehcache cache, Pool pool, MemoryStore.BackingFactory factory, SearchManager searchManager)
cache
- the cachepool
- the pool tracking the on-heap usagesearchManager
- the search managerMethod Detail |
---|
protected static int getInitialCapacityForLoadFactor(int maximumSizeGoal, float loadFactor)
maximumSizeGoal
- the desired maximum size goalloadFactor
- the load factor
public static Store create(Ehcache cache, Pool pool)
cache
- the cachepool
- the pool tracking the on-heap usage
protected static net.sf.ehcache.store.BruteForceSource createBruteForceSource(MemoryStore memoryStore, CacheConfiguration cacheConfiguration)
memoryStore
- the underlying store acting as sourcecacheConfiguration
- the cache configuration
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 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 void maxEntriesInCacheChanged(long oldValue, long newValue)
maxEntriesInCacheChanged
in interface CacheConfigurationListener
oldValue
- old valuenewValue
- new valuepublic 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 void setAttributeExtractors(Map<String,AttributeExtractor> extractors)
AbstractStore
setAttributeExtractors
in interface Store
setAttributeExtractors
in class AbstractStore
public 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 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 |