|
ehcache | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.ehcache.store.DiskStore
public class DiskStore
A disk store implementation.
As of ehcache-1.2 (v1.41 of this file) DiskStore has been changed to a mix of finer grained locking using synchronized collections and synchronizing on the whole instance, as was the case with earlier versions. The DiskStore, as of ehcache-1.2.4, supports eviction using an LFU policy, if a maximum disk store size is set. LFU uses statistics held at the Element level which survive moving between maps in the MemoryStore and DiskStores. As of ehcache-2.0, a cache can be configured with a DiskStore with multiple stripes. This enables much higher throughput.
Field Summary | |
---|---|
static java.lang.String |
AUTO_DISK_PATH_DIRECTORY_PREFIX
If the CacheManager needs to resolve a conflict with the disk path, it will create a subdirectory in the given disk path with this prefix followed by a number. |
Constructor Summary | |
---|---|
protected |
DiskStore(Ehcache cache,
java.lang.String diskPath)
Creates a disk store. |
Method Summary | |
---|---|
boolean |
bufferFull()
In some circumstances data can be written so quickly to the spool that the VM runs out of memory while waiting for the spooling to disk. |
float |
calculateDataFileSparseness()
The design of the layout on the data file means that there will be small gaps created when DiskElements are reused. |
boolean |
containsKey(java.lang.Object key)
An unsynchronized and very low cost check to see if a key is in the Store. |
static Store |
create(Cache cache,
java.lang.String diskStorePath)
A factory method to create a DiskStore. |
protected void |
deleteFilesInAutoGeneratedDirectory()
Delete files in the auto generated directory. |
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()
Shuts down the disk store in preparation for cache shutdown If a VM crash happens, the shutdown hook will not run. |
void |
expireElements()
Removes expired elements. |
void |
flush()
Flush the spool if persistent, so we don't lose any data. |
static java.lang.String |
generateUniqueDirectory()
Generates a unique directory name for use in automatically creating a diskStorePath where there is a conflict. |
Element |
get(java.lang.Object key)
Gets an Element from the Disk Store. |
java.lang.String |
getDataFileName()
Creates a file system safe data file. |
java.lang.String |
getDataFilePath()
|
long |
getDataFileSize()
|
Policy |
getEvictionPolicy()
|
java.lang.String |
getIndexFileName()
|
long |
getIndexFileSize()
|
java.lang.Object |
getInternalContext()
This should not be used, and will generally return null |
java.lang.Object[] |
getKeyArray()
Gets an Array of the keys for all elements in the disk store. |
Element |
getQuiet(java.lang.Object key)
Gets an Element from the Disk Store, without updating statistics |
int |
getSize()
Returns the current store size in number of Elements. |
long |
getSizeInBytes()
Gets the size of the store, in bytes. |
Status |
getStatus()
Returns the store status. |
int |
getTerracottaClusteredSize()
Returns nothing since a disk store isn't clustered |
long |
getTotalFileSize()
|
long |
getUsedDataSize()
When elements are deleted, spaces are left in the file. |
boolean |
isCacheCoherent()
Indicates whether this store provides a coherent view of all the elements in a cache. |
boolean |
isClusterCoherent()
Returns true if the cache is in coherent mode cluster-wide. |
boolean |
isNodeCoherent()
Returns true if the cache is in coherent mode for the current node. |
boolean |
isSpoolThreadAlive()
The spool thread is started when the disk store is created. |
static net.sf.ehcache.store.DiskStore.DiskElement |
leastHit(net.sf.ehcache.store.DiskStore.DiskElement[] sampledElements,
net.sf.ehcache.store.DiskStore.DiskElement justAdded)
Finds the least hit of the sampled elements provided |
void |
loggingEnabledChanged(boolean oldValue,
boolean newValue)
Indicates a change in the configuration for enable/disable logging |
void |
memoryCapacityChanged(int oldCapacity,
int newCapacity)
Indicates a change in the configurations memory store capacity |
boolean |
put(Element element)
Puts an element into the disk store. |
boolean |
putWithWriter(Element element,
CacheWriterManager writerManager)
Puts an item into the store and the cache writer manager in an atomic operation |
void |
registered(CacheConfiguration config)
Indicates that this listener was registered with the given configuration |
Element |
remove(java.lang.Object key)
Removes an item from the disk store. |
void |
removeAll()
Remove all of the elements from the store. |
Element |
removeWithWriter(java.lang.Object key,
CacheWriterManager writerManager)
Removes an item from the store and the cache writer manager in an atomic operation. |
void |
setEvictionPolicy(Policy policy)
Sets the eviction policy strategy. |
void |
setNodeCoherent(boolean coherent)
Sets the cache in coherent or incoherent mode for the current node depending on the parameter. |
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 |
java.lang.String |
toString()
Returns a String representation of the DiskStore |
void |
waitUntilClusterCoherent()
This method waits until the cache is in coherent mode in all the connected nodes. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String AUTO_DISK_PATH_DIRECTORY_PREFIX
Constructor Detail |
---|
protected DiskStore(Ehcache cache, java.lang.String diskPath)
cache
- the Cache
that the store is part ofdiskPath
- the directory in which to create data and index filesMethod Detail |
---|
public static Store create(Cache cache, java.lang.String diskStorePath)
cache
- diskStorePath
-
public final Element get(java.lang.Object key)
Element
from the Disk Store.
get
in interface Store
public final boolean containsKey(java.lang.Object key)
containsKey
in interface Store
key
- The Element key
public final Element getQuiet(java.lang.Object key)
Element
from the Disk Store, without updating statistics
getQuiet
in interface Store
get(Object)
public final java.lang.Object[] getKeyArray()
getKeyArray
in interface Store
Serializable
keyspublic final int getSize()
getSize
in interface Store
getDataFileSize()
public final int getTerracottaClusteredSize()
getTerracottaClusteredSize
in interface Store
public long getSizeInBytes()
getSizeInBytes
in interface Store
public final Status getStatus()
getStatus
in interface Store
public final boolean put(Element element)
put
in interface Store
public boolean putWithWriter(Element element, CacheWriterManager writerManager) throws CacheException
putWithWriter
in interface Store
CacheException
public boolean bufferFull()
bufferFull
in interface Store
public final Element remove(java.lang.Object key)
remove
in interface Store
public Element removeWithWriter(java.lang.Object key, CacheWriterManager writerManager)
removeWithWriter
in interface Store
public final void removeAll()
CacheEventListener
s they are notified of the expiry or removal
of the Element
as each is removed.
removeAll
in interface Store
public final void dispose()
dispose
in interface Store
protected void deleteFilesInAutoGeneratedDirectory()
public final void flush()
flush
in interface Store
public void expireElements()
expireElements
in interface Store
public final java.lang.String toString()
String
representation of the DiskStore
toString
in class java.lang.Object
public static java.lang.String generateUniqueDirectory()
AUTO_DISK_PATH_DIRECTORY_PREFIX
followed by "_" followed by the current
time as a long e.g. ehcache_auto_created_1149389837006public 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 memoryCapacityChanged(int oldCapacity, int newCapacity)
memoryCapacityChanged
in interface CacheConfigurationListener
oldCapacity
- previous capacitynewCapacity
- new capacitypublic void loggingEnabledChanged(boolean oldValue, boolean newValue)
loggingEnabledChanged
in interface CacheConfigurationListener
oldValue
- old value whether logging was enabled or notnewValue
- new value whether logging was enabled or notpublic void registered(CacheConfiguration config)
registered
in interface CacheConfigurationListener
public void deregistered(CacheConfiguration config)
deregistered
in interface CacheConfigurationListener
public final long getTotalFileSize()
public final long getDataFileSize()
public final float calculateDataFileSparseness()
public final long getUsedDataSize()
getDataFileSize()
as a measure of fragmentation.
public final long getIndexFileSize()
public final java.lang.String getDataFileName()
/
are replaced with _
so there are no unwanted side effects.
public final java.lang.String getDataFilePath()
public final java.lang.String getIndexFileName()
public final boolean isSpoolThreadAlive()
dispose()
method is called,
at which time it should be interrupted and then die.
public static net.sf.ehcache.store.DiskStore.DiskElement leastHit(net.sf.ehcache.store.DiskStore.DiskElement[] sampledElements, net.sf.ehcache.store.DiskStore.DiskElement justAdded)
sampledElements
- this should be a random subset of the populationjustAdded
- we never want to select the element just added. May be null.
public Policy getEvictionPolicy()
getEvictionPolicy
in interface Store
setEvictionPolicy(Policy)
public void setEvictionPolicy(Policy policy)
setEvictionPolicy
in interface Store
policy
- the new policypublic java.lang.Object getInternalContext()
getInternalContext
in interface Store
public boolean isCacheCoherent()
Store.isClusterCoherent()
(introduced since 2.0)
Use Store.isNodeCoherent()
to find out if the cache is coherent in the current node in the cluster
isCacheCoherent
in interface Store
true
if the store is coherent; or false
if the
store potentially splits the cache storage with another store or
isn't internally coherentpublic boolean isClusterCoherent()
isClusterCoherent
in interface Store
public boolean isNodeCoherent()
isNodeCoherent
in interface Store
public void setNodeCoherent(boolean coherent)
setNodeCoherent(true)
when the cache is already in coherent mode or
calling setNodeCoherent(false)
when already in incoherent mode will be a no-op.
It applies to coherent clustering mechanisms only e.g. Terracotta
setNodeCoherent
in interface Store
coherent
- true transitions to coherent mode, false to incoherent modepublic void waitUntilClusterCoherent()
waitUntilClusterCoherent
in interface Store
|
ehcache | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |