This uses java. as its backing map. It uses the java. LRU
feature. LRU for this implementation means least recently accessed.
| Modifier and Type | Class and Description |
|---|---|
| public class | LruMemoryStore.SpoolingLinkedHashMap
An extension of LinkedHashMap which overrides |
| Modifier and Type | Field 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 | |
| private final OperationObserver | |
| private static final Logger | |
| protected Map | map
Map where items are stored by key. |
| protected long | maximumSize
The maximum size of the store (0 == no limit) |
| private final OperationObserver | |
| private final OperationObserver | |
| protected Status | status
status. |
| Access | Constructor and Description |
|---|---|
| public | LruMemoryStore(Ehcache cache, Store diskStore)
Constructor for the LruMemoryStore object
The backing |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | bufferFull()
Implements net. |
| protected final void | |
| 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.The Element key key)Implements net. |
| public boolean | containsKeyInMemory(Object
The Element key key)Implements net. |
| public boolean | containsKeyOffHeap(Object
The Element key key)Implements net. |
| public boolean | containsKeyOnDisk(Object
The Element key key)Implements net. |
| private boolean | |
| public final synchronized void | |
| protected void | |
| protected final void | |
| public void | |
| public final void | flush()
Implements net. |
| public final synchronized Element | Returns: the element, or null if there was no match for the keythe cache key key)Implements net. |
| pack-priv Map | |
| public Policy | Returns: the current eviction policy. This may not be the configured policy, if it has been dynamically set.
|
| public Policy | |
| public int | getInMemorySize()
Implements net. |
| public long | getInMemorySizeInBytes()
Implements net. |
| public Object | getInternalContext()
Implements net. |
| public final synchronized List | Returns: An Object[]Implements net. |
| public Object | getMBean()
Implements net. |
| public int | getOffHeapSize()
Implements net. |
| public long | getOffHeapSizeInBytes()
Implements net. |
| public int | getOnDiskSize()
Implements net. |
| public long | getOnDiskSizeInBytes()
Implements net. |
| public final synchronized Element | Returns: the element, or null if there was no match for the keythe cache key key)Implements net. |
| public final int | Returns: The size valueImplements net. |
| public final synchronized long | Returns: the size, in bytesMeasures the size of the memory store by using the sizeof engine. |
| public final Status | |
| public final int | Returns: returns 0Implements net. |
| protected final boolean | |
| protected final void | |
| public final boolean | put(Element
the element to add element)Implements net. |
| public Element | putIfAbsent(Element
element to be added element)Implements net. |
| private synchronized boolean | |
| public final boolean | putWithWriter(Element element, CacheWriterManager writerManager)
Implements net. |
| public final Element | Returns: the Element if one was found, else nullthe key of the Element, usually a String key)Implements net. |
| public final synchronized void | removeAll()
Implements net. |
| public Element | removeElement(Element
Element to be removed element, ElementValueComparator ElementValueComparator to use to compare elements comparator)Implements net. |
| private synchronized Element | |
| public final Element | removeWithWriter(Object key, CacheWriterManager writerManager)
Implements net. |
| 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. |
| public Element | replace(Element
Element to be cached element)Implements net. |
| public void | |
| public void | setInMemoryEvictionPolicy(Policy
the new policy policy)Implements net. |
| protected final void | |
| protected void |
| cache | back to summary |
|---|---|
| protected Ehcache cache The cache this store is associated with. | |
| cachePinned | back to summary |
|---|---|
| private final boolean cachePinned | |
| copyStrategyHandler | back to summary |
|---|---|
| private final CopyStrategyHandler copyStrategyHandler | |
| diskStore | back to summary |
|---|---|
| protected final Store diskStore The DiskStore associated with this MemoryStore. | |
| elementPinningEnabled | back to summary |
|---|---|
| private final boolean elementPinningEnabled | |
| evictionObserver | back to summary |
|---|---|
| private final OperationObserver<CacheOperationOutcomes. | |
| getObserver | back to summary |
|---|---|
| private final OperationObserver<StoreOperationOutcomes. | |
| LOG | back to summary |
|---|---|
| private static final Logger LOG | |
| map | back to summary |
|---|---|
| protected Map<K, V> map Map where items are stored by key. | |
| maximumSize | back to summary |
|---|---|
| protected long maximumSize The maximum size of the store (0 == no limit) | |
| putObserver | back to summary |
|---|---|
| private final OperationObserver<StoreOperationOutcomes. | |
| removeObserver | back to summary |
|---|---|
| private final OperationObserver<StoreOperationOutcomes. | |
| status | back to summary |
|---|---|
| protected Status status status. | |
| LruMemoryStore | back to summary |
|---|---|
| public LruMemoryStore(Ehcache cache, Store diskStore) Constructor for the LruMemoryStore object
The backing | |
| bufferFull | back to summary |
|---|---|
| public boolean bufferFull() Implements net. Memory stores are never backed up and always return false
| |
| clear | back to summary |
|---|---|
| protected final void clear() Clears any data structures and places it back to its state when it was first created. | |
| containsKey | back to summary |
|---|---|
| public final boolean containsKey(Object key) Implements net. An unsynchronized check to see if a key is in the Store. No check is made to see if the Element is expired.
| |
| containsKeyInMemory | back to summary |
|---|---|
| public boolean containsKeyInMemory(Object key) Implements net. Doc from net. A check to see if a key is in the Store and is currently held in memory.
| |
| containsKeyOffHeap | back to summary |
|---|---|
| public boolean containsKeyOffHeap(Object key) Implements net. Doc from net. A check to see if a key is in the Store and is currently held off-heap.
| |
| containsKeyOnDisk | back to summary |
|---|---|
| public boolean containsKeyOnDisk(Object key) Implements net. Doc from net. A check to see if a key is in the Store and is currently held on disk.
| |
| determineCachePinned | back to summary |
|---|---|
| private boolean determineCachePinned(CacheConfiguration cacheConfiguration) | |
| dispose | back to summary |
|---|---|
| public final synchronized void dispose() Implements net. Prepares for shutdown. | |
| doPut | back to summary |
|---|---|
| protected void doPut(Element element) throws CacheException Allow specialised actions over adding the element to the map. | |
| evict | back to summary |
|---|---|
| protected final void evict(Element element) throws CacheException Evict the
Evict means that the
| |
| expireElements | back to summary |
|---|---|
| public void expireElements() Implements net. Expire all elsments. This is a default implementation which does nothing. Expiry on demand is only implemented for disk stores. | |
| flush | back to summary |
|---|---|
| public final void flush() Implements net. Flush to disk only if the cache is diskPersistent. | |
| get | back to summary |
|---|---|
| public final synchronized Element get(Object key) Implements net. Gets an item from the cache.
The last access time in | |
| getBackingMap | back to summary |
|---|---|
| pack-priv Map Package local access to the map for testing | |
| getEvictionPolicy | back to summary |
|---|---|
public Policy getEvictionPolicy()
| |
| getInMemoryEvictionPolicy | back to summary |
|---|---|
| public Policy getInMemoryEvictionPolicy() Implements net.
| |
| getInMemorySize | back to summary |
|---|---|
| public int getInMemorySize() Implements net. Doc from net. Returns the current local in-memory store size
| |
| getInMemorySizeInBytes | back to summary |
|---|---|
| public long getInMemorySizeInBytes() Implements net. Doc from net. 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.
| |
| getInternalContext | back to summary |
|---|---|
| public Object getInternalContext() Implements net. Doc from net. This should not be used, and will generally return null
| |
| getKeys | back to summary |
|---|---|
| public final synchronized List Implements net. Gets an Array of the keys for all elements in the memory cache. Does not check for expired entries
| |
| getMBean | back to summary |
|---|---|
| public Object getMBean() Implements net. Doc from net. Optional implementation specific MBean exposed by the store.
| |
| getOffHeapSize | back to summary |
|---|---|
| public int getOffHeapSize() Implements net. Doc from net. Returns the current local off-heap store size
| |
| getOffHeapSizeInBytes | back to summary |
|---|---|
| public long getOffHeapSizeInBytes() Implements net. Doc from net. Gets the size of the off-heap portion of the store, in bytes.
| |
| getOnDiskSize | back to summary |
|---|---|
| public int getOnDiskSize() Implements net. Doc from net. Returns the current local on-disk store size
| |
| getOnDiskSizeInBytes | back to summary |
|---|---|
| public long getOnDiskSizeInBytes() Implements net. Doc from net. Gets the size of the on-disk portion of the store, in bytes.
| |
| getQuiet | back to summary |
|---|---|
| public final synchronized Element getQuiet(Object key) Implements net. Gets an item from the cache, without updating statistics. | |
| getSize | back to summary |
|---|---|
| public final int getSize() Implements net. Returns the current cache size.
| |
| getSizeInBytes | back 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
| |
| getStatus | back to summary |
|---|---|
| public final Status getStatus() Implements net. Gets the status of the MemoryStore. | |
| getTerracottaClusteredSize | back to summary |
|---|---|
| public final int getTerracottaClusteredSize() Implements net. Returns nothing since a disk store isn't clustered
| |
| isFull | back to summary |
|---|---|
| protected final boolean isFull() An algorithm to tell if the MemoryStore is at or beyond its carrying capacity. | |
| notifyExpiry | back to summary |
|---|---|
| protected final void notifyExpiry(Element element) Before eviction elements are checked. | |
| put | back to summary |
|---|---|
| public final boolean put(Element element) throws CacheException Implements net. Puts an item in the cache. Note that this automatically results in
| |
| putIfAbsent | back to summary |
|---|---|
| public Element putIfAbsent(Element element) throws NullPointerException Implements net. Unsupported in LruMemoryStore
| |
| putInternal | back to summary |
|---|---|
| private synchronized boolean putInternal(Element element, CacheWriterManager writerManager) throws CacheException | |
| putWithWriter | back to summary |
|---|---|
| public final boolean putWithWriter(Element element, CacheWriterManager writerManager) throws CacheException Implements net. Doc from net. Puts an item into the store and the cache writer manager in an atomic operation
| |
| remove | back to summary |
|---|---|
| public final Element remove(Object key) Implements net. Removes an Element from the store. | |
| removeAll | back to summary |
|---|---|
| public final synchronized void removeAll() throws CacheException Implements net. Remove all of the elements from the store. | |
| removeElement | back to summary |
|---|---|
| public Element removeElement(Element element, ElementValueComparator comparator) throws NullPointerException Implements net. Unsupported in LruMemoryStore
| |
| removeInternal | back to summary |
|---|---|
| private synchronized Element removeInternal(Object key, CacheWriterManager writerManager) throws CacheException | |
| removeWithWriter | back to summary |
|---|---|
| public final Element removeWithWriter(Object key, CacheWriterManager writerManager) throws CacheException Implements net. Doc from net. Removes an item from the store and the cache writer manager in an atomic operation. | |
| replace | back to summary |
|---|---|
| public boolean replace(Element old, Element element, ElementValueComparator comparator) throws NullPointerException, IllegalArgumentException Implements net. Unsupported in LruMemoryStore
| |
| replace | back to summary |
|---|---|
| public Element replace(Element element) throws NullPointerException Implements net. Unsupported in LruMemoryStore
| |
| setEvictionPolicy | back 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.
| |
| setInMemoryEvictionPolicy | back to summary |
|---|---|
| public void setInMemoryEvictionPolicy(Policy policy) Implements net. Doc from net. 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.
| |
| spoolAllToDisk | back 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. | |
| spoolToDisk | back 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
| |
removeEldestEntry
to persist cache entries to the auxiliary cache before they are removed.
This implementation also provides LRU by access order.
| Modifier and Type | Field and Description |
|---|---|
| private static final float | |
| private static final int |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method 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. Implements java. |
| protected final boolean | Returns: true if the eldest entry should be removed from the map; false if it should be retained.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. eldestOverrides java. |
| private boolean | Returns: true if the LRU element should be removedRelies on being called from a synchronized method |
| GROWTH_FACTOR | back to summary |
|---|---|
| private static final float GROWTH_FACTOR | |
| INITIAL_CAPACITY | back to summary |
|---|---|
| private static final int INITIAL_CAPACITY | |
| SpoolingLinkedHashMap | back to summary |
|---|---|
| public SpoolingLinkedHashMap() Default constructor. Will create an initial capacity of 100, a loading of .75 and LRU by access order. | |
| put | back to summary |
|---|---|
| public Object put(Object key, Object value) Overrides java. Implements java. Doc from java. 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
| |
| removeEldestEntry | back to summary |
|---|---|
| protected final boolean removeEldestEntry(Map. Overrides java. 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:
| |
| removeLeastRecentlyUsedElement | back to summary |
|---|---|
| private boolean removeLeastRecentlyUsedElement(Element element) throws CacheException Relies on being called from a synchronized method
| |