public class MemoryStore extends AbstractStore implements CacheConfigurationListener, Store
| Modifier and Type | Class and Description |
|---|---|
protected static interface |
MemoryStore.BackingFactory
Factory interface to create a MemoryStore backing.
|
| Modifier and Type | Field and Description |
|---|---|
protected org.terracotta.statistics.observer.OperationObserver<CacheOperationOutcomes.EvictionOutcome> |
evictionObserver
Eviction outcome observer
|
attributeExtractors, searchManagerCLUSTER_COHERENT, NODE_COHERENT| Modifier | Constructor and Description |
|---|---|
protected |
MemoryStore(Ehcache cache,
Pool pool,
MemoryStore.BackingFactory factory,
SearchManager searchManager)
Constructs things that all MemoryStores have in common.
|
| Modifier and Type | Method and Description |
|---|---|
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
|
addStoreListener, executeQuery, getAll, getAllQuiet, getEventListenerList, getSearchAttribute, getSearchAttributes, isCacheCoherent, isClusterCoherent, isNodeCoherent, putAll, removeAll, removeStoreListener, setNodeCoherent, waitUntilClusterCoherentclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddStoreListener, executeQuery, getAll, getAllQuiet, getSearchAttribute, getSearchAttributes, isCacheCoherent, isClusterCoherent, isNodeCoherent, putAll, removeAll, removeStoreListener, setNodeCoherent, waitUntilClusterCoherentprotected final org.terracotta.statistics.observer.OperationObserver<CacheOperationOutcomes.EvictionOutcome> evictionObserver
protected MemoryStore(Ehcache cache, Pool pool, MemoryStore.BackingFactory factory, SearchManager searchManager)
cache - the cachepool - the pool tracking the on-heap usagesearchManager - the search managerprotected static int getInitialCapacityForLoadFactor(int maximumSizeGoal,
float loadFactor)
maximumSizeGoal - the desired maximum size goalloadFactor - the load factorpublic static Store create(Ehcache cache, Pool pool)
cache - the cachepool - the pool tracking the on-heap usageprotected static net.sf.ehcache.store.BruteForceSource createBruteForceSource(MemoryStore memoryStore, CacheConfiguration cacheConfiguration)
memoryStore - the underlying store acting as sourcecacheConfiguration - the cache configurationpublic boolean put(Element element) throws CacheException
put in interface Storeelement - the element to addCacheExceptionpublic boolean putWithWriter(Element element, CacheWriterManager writerManager) throws CacheException
putWithWriter in interface StoreCacheExceptionpublic final Element get(Object key)
The last access time in Element is updated.
public final Element getQuiet(Object key)
public final Element removeWithWriter(Object key, CacheWriterManager writerManager) throws CacheException
removeWithWriter in interface StoreCacheExceptionpublic final boolean bufferFull()
bufferFull in interface Storepublic void expireElements()
This is a default implementation which does nothing. Expiration on demand is only implemented for disk stores.
expireElements in interface Storeprotected Element expireElement(Object key)
key - the keypublic final void removeAll()
throws CacheException
removeAll in interface StoreCacheExceptionpublic void flush()
public final List<?> getKeys()
Does not check for expired entries
protected Set<?> keySet()
public final int getSize()
public final int getTerracottaClusteredSize()
getTerracottaClusteredSize in interface Storepublic final boolean containsKey(Object key)
containsKey in interface Storekey - The Element keyprotected void notifyDirectEviction(Element element)
element - the evicted elementpublic final boolean isFull()
public final boolean canPutWithoutEvicting(Element element)
element - the elementpublic Object getInternalContext()
getInternalContext in interface Storepublic final Status getStatus()
public void timeToIdleChanged(long oldTti,
long newTti)
timeToIdleChanged in interface CacheConfigurationListeneroldTti - previous time to idle valuenewTti - new time to idle valuepublic void timeToLiveChanged(long oldTtl,
long newTtl)
timeToLiveChanged in interface CacheConfigurationListeneroldTtl - previous time to live valuenewTtl - new time to live valuepublic void diskCapacityChanged(int oldCapacity,
int newCapacity)
diskCapacityChanged in interface CacheConfigurationListeneroldCapacity - previous capacitynewCapacity - new capacitypublic void loggingChanged(boolean oldValue,
boolean newValue)
loggingChanged in interface CacheConfigurationListeneroldValue - 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 CacheConfigurationListeneroldCapacity - previous capacitynewCapacity - new capacitypublic void registered(CacheConfiguration config)
registered in interface CacheConfigurationListenerpublic void deregistered(CacheConfiguration config)
deregistered in interface CacheConfigurationListenerpublic void maxBytesLocalHeapChanged(long oldValue,
long newValue)
maxBytesLocalHeapChanged in interface CacheConfigurationListeneroldValue - old value in bytesnewValue - new value in bytespublic void maxBytesLocalDiskChanged(long oldValue,
long newValue)
maxBytesLocalDiskChanged in interface CacheConfigurationListeneroldValue - old value in bytesnewValue - new value in bytespublic void maxEntriesInCacheChanged(long oldValue,
long newValue)
maxEntriesInCacheChanged in interface CacheConfigurationListeneroldValue - old valuenewValue - new valuepublic boolean containsKeyInMemory(Object key)
containsKeyInMemory in interface Storekey - The Element keypublic boolean containsKeyOffHeap(Object key)
containsKeyOffHeap in interface Storekey - The Element keypublic boolean containsKeyOnDisk(Object key)
containsKeyOnDisk in interface Storekey - The Element keypublic Policy getInMemoryEvictionPolicy()
getInMemoryEvictionPolicy in interface StoreStore.setInMemoryEvictionPolicy(Policy)public int getInMemorySize()
getInMemorySize in interface Storepublic long getInMemorySizeInBytes()
This method may be expensive to run, depending on implementation. Implementers may choose to return an approximate size.
getInMemorySizeInBytes in interface Storepublic int getOffHeapSize()
getOffHeapSize in interface Storepublic long getOffHeapSizeInBytes()
getOffHeapSizeInBytes in interface Storepublic int getOnDiskSize()
getOnDiskSize in interface Storepublic long getOnDiskSizeInBytes()
getOnDiskSizeInBytes in interface Storepublic boolean hasAbortedSizeOf()
hasAbortedSizeOf in interface StorehasAbortedSizeOf in class AbstractStorepublic void setInMemoryEvictionPolicy(Policy policy)
setInMemoryEvictionPolicy in interface Storepolicy - the new policypublic void setAttributeExtractors(Map<String,AttributeExtractor> extractors)
AbstractStoresetAttributeExtractors in interface StoresetAttributeExtractors in class AbstractStorepublic Element putIfAbsent(Element element) throws NullPointerException
putIfAbsent in interface Storeelement - element to be addedNullPointerException - if the element is null, or has a null keyprotected boolean evict(Element element)
element - the element to be evictedpublic Element removeElement(Element element, ElementValueComparator comparator) throws NullPointerException
removeElement in interface Storeelement - 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
replace in interface Storeold - 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
replace in interface Storeelement - Element to be cachedNullPointerException - if the Element is null or has a null keypublic Object getMBean()
public Collection<Element> elementSet()
public void recalculateSize(Object key)
AbstractStorerecalculateSize in interface StorerecalculateSize in class AbstractStorekey - the keyCopyright 2001-2021, Terracotta, Inc.