|
ehcache | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.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.
Field Summary | |
---|---|
protected Ehcache |
cache
The cache this store is associated with. |
protected static int |
CONCURRENCY_LEVEL
Set optimisation for 100 concurrent threads. |
protected static float |
DEFAULT_LOAD_FACTOR
This is the default from ConcurrentHashMap . |
protected Store |
diskStore
The DiskStore associated with this MemoryStore. |
protected java.util.Map |
map
Map where items are stored by key. |
protected int |
maximumSize
The maximum size of the store |
protected Policy |
policy
The eviction policy to use |
protected Status |
status
status. |
protected static int |
TOO_LARGE_TO_EFFICIENTLY_ITERATE
This number is magic. |
protected boolean |
useKeySample
when sampling elements, whether to iterate or to use the keySample array for faster random access |
Constructor Summary | |
---|---|
protected |
MemoryStore(Ehcache cache,
Store diskStore)
Constructs things that all MemoryStores have in common. |
Method Summary | |
---|---|
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(java.lang.Object key)
A check to see if a key is in the Store. |
static MemoryStore |
create(Ehcache cache,
Store diskStore)
A factory method to create a MemoryStore. |
protected void |
determineEvictionPolicy(Ehcache cache)
Chooses the Policy from the cache configuration |
void |
dispose()
Prepares for shutdown. |
protected void |
doPut(Element elementJustAdded)
Puts an element into the store |
protected void |
evict(Element element)
Evict the Element . |
void |
expireElements()
Expire all elsments. |
protected Element |
findEvictionCandidate(Element elementJustAdded)
Find a "relatively" unused element, but not the element just added. |
void |
flush()
Flush to disk only if the cache is diskPersistent. |
Element |
get(java.lang.Object key)
Gets an item from the cache. |
Policy |
getEvictionPolicy()
|
java.lang.Object[] |
getKeyArray()
Gets an Array of the keys for all elements in the memory cache. |
Element |
getQuiet(java.lang.Object key)
Gets an item from the cache, without updating statistics. |
int |
getSize()
Returns the current store size. |
long |
getSizeInBytes()
Measures the size of the memory store by measuring the serialized size of all elements. |
Status |
getStatus()
Gets the status of the MemoryStore. |
protected int |
incrementIndex()
A bounds-safe incrementer, which loops back to zero when it exceeds the array size |
protected boolean |
isFull()
An algorithm to tell if the MemoryStore is at or beyond its carrying capacity. |
protected void |
notifyExpiry(Element element)
Before eviction elements are checked. |
void |
put(Element element)
Puts an item in the store. |
Element |
remove(java.lang.Object key)
Removes an Element from the store. |
void |
removeAll()
Remove all of the elements from the store. |
protected void |
removeElementChosenByEvictionPolicy(Element elementJustAdded)
Removes the element chosen by the eviction policy |
protected Element[] |
sampleElements(int size)
Uses random numbers to sample the entire map. |
protected Element[] |
sampleElementsViaKeyArray()
Uses random numbers to sample the entire map. |
protected void |
saveKey(Element elementJustAdded)
Saves the key to our fast access AtomicReferenceArray |
void |
setEvictionPolicy(Policy policy)
Sets the policy. |
protected void |
spoolAllToDisk()
Spools all elements to disk, in preparation for shutdown. |
protected void |
spoolToDisk(Element element)
Puts the element in the DiskStore. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final int TOO_LARGE_TO_EFFICIENTLY_ITERATE
protected static final float DEFAULT_LOAD_FACTOR
ConcurrentHashMap
. It should never be used, because
we size the map to the max size of the store.
protected static final int CONCURRENCY_LEVEL
protected Policy policy
protected boolean useKeySample
protected Ehcache cache
protected java.util.Map map
protected final Store diskStore
protected Status status
protected int maximumSize
Constructor Detail |
---|
protected MemoryStore(Ehcache cache, Store diskStore)
cache
- diskStore
- Method Detail |
---|
public static MemoryStore create(Ehcache cache, Store diskStore)
cache
- diskStore
-
public final void put(Element element) throws CacheException
put
in interface Store
element
- the element to add
CacheException
public final Element get(java.lang.Object key)
Element
is updated.
get
in interface Store
key
- the cache key
public final Element getQuiet(java.lang.Object key)
getQuiet
in interface Store
key
- the cache key
public final Element remove(java.lang.Object key)
remove
in interface Store
key
- the key of the Element, usually a String
public final void removeAll() throws CacheException
removeAll
in interface Store
CacheException
protected final void clear()
public final void dispose()
dispose
in interface Store
public final void flush()
flush
in interface Store
protected final void spoolAllToDisk()
protected void spoolToDisk(Element element)
element
- The Elementpublic final Status getStatus()
getStatus
in interface Store
public final java.lang.Object[] getKeyArray()
getKeyArray
in interface Store
public final int getSize()
getSize
in interface Store
public final boolean containsKey(java.lang.Object key)
containsKey
in interface Store
key
- The Element key
public final long getSizeInBytes() throws CacheException
getSizeInBytes
in interface Store
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()
expireElements
in interface Store
public boolean bufferFull()
bufferFull
in interface Store
protected void doPut(Element elementJustAdded)
protected void saveKey(Element elementJustAdded)
elementJustAdded
- the new elementprotected int incrementIndex()
protected void removeElementChosenByEvictionPolicy(Element elementJustAdded)
elementJustAdded
- it is possible for this to be nullprotected final Element findEvictionCandidate(Element elementJustAdded)
protected Element[] sampleElementsViaKeyArray()
protected Element[] sampleElements(int size)
ConcurrentHashMap
iterator.
protected void determineEvictionPolicy(Ehcache cache)
cache
- public Policy getEvictionPolicy()
getEvictionPolicy
in interface Store
Store.setEvictionPolicy(Policy)
public void setEvictionPolicy(Policy policy)
setEvictionPolicy
in interface Store
policy
- a new policy to be used in evicting elements in this store
|
ehcache | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |