|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.ehcache.Cache
Cache is the central class in EHCache. Caches have Element
s and are managed
by the CacheManager
. The Cache performs logical actions. It delegates physical
implementations to its Store
s.
CacheManager
. A Cache thus obtained
is guaranteed to have status STATUS_ALIVE
. This status is checked for any method which
throws IllegalStateException
and the same thrown if it is not alive. This would normally
happen if a call is made after CacheManager.shutdown()
is invoked.
Cache is threadsafe.
Statistics on cache usage are collected and made available through public methods.
Field Summary | |
static java.lang.String |
DEFAULT_CACHE_NAME
A reserved word for cache names. |
static int |
STATUS_ALIVE
The cache is alive. |
static int |
STATUS_DISPOSED
The cache is uninitialised. |
static int |
STATUS_UNINITIALISED
The cache is uninitialised. |
Constructor Summary | |
Cache(java.lang.String name,
int maximumSize,
boolean overflowToDisk,
boolean eternal,
long timeToLive,
long timeToIdle)
Full Constructor. |
Method Summary | |
java.lang.Object |
clone()
Clones a cache. |
(package private) void |
dispose()
Flushes all cache items from memory to auxilliary caches and close the auxilliary caches. |
Element |
get(java.io.Serializable key)
Gets an element from the cache. |
(package private) DiskStore |
getDiskStore()
Gets the internal DiskStore. |
int |
getDiskStoreHitCount()
Number of times a requested item was found in the Disk Store |
int |
getDiskStoreSize()
Returns the number of elements in the disk store. |
int |
getHitCount()
Number of times a requested item was found in the cache |
java.util.List |
getKeys()
Returns the keys of all elements in the cache The List returned is not live. |
int |
getMaxElementsInMemory()
Gets the maximum number of elements to hold in memory |
(package private) MemoryStore |
getMemoryStore()
Gets the internal MemoryStore. |
int |
getMemoryStoreHitCount()
Number of times a requested item was found in the Memory Store |
int |
getMemoryStoreSize()
Returns the number of elements in the memory store. |
int |
getMissCountExpired()
Number of times a requested element was found but was expired |
int |
getMissCountNotFound()
Number of times a requested element was not found in the cache. |
java.lang.String |
getName()
Gets the cache name |
int |
getSize()
Gets the size of the cache. |
int |
getStatus()
Gets the status attribute of the Store object |
long |
getTimeToIdleSeconds()
Gets timeToIdleSeconds |
long |
getTimeToLiveSeconds()
Gets timeToLiveSeconds |
(package private) void |
initialise(Configuration configuration)
Newly created caches do not have a MemoryStore or a DiskStore . |
boolean |
isEternal()
Are elements eternal |
boolean |
isExpired(Element element)
Checks whether this cache element has expired. |
boolean |
isOverflowToDisk()
Does the overflow go to disk |
void |
put(Element element)
Put an element in the cache. |
boolean |
remove(java.io.Serializable key)
Removes an Element from the Cache. |
void |
removeAll()
Removes all cached items. |
(package private) void |
setName(java.lang.String name)
Sets the name |
java.lang.String |
toString()
Returns a String representation of Cache |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final java.lang.String DEFAULT_CACHE_NAME
public static final int STATUS_UNINITIALISED
public static final int STATUS_ALIVE
public static final int STATUS_DISPOSED
Constructor Detail |
public Cache(java.lang.String name, int maximumSize, boolean overflowToDisk, boolean eternal, long timeToLive, long timeToIdle)
Configurator
and clients can create these.
A client can specify their own settings here and pass the Cache
object
into CacheManager.addCache(java.lang.String)
to specify parameters other than the defaults.
Only the CacheManager can initialise them.
Method Detail |
void initialise(Configuration configuration)
MemoryStore
or a DiskStore
.
This method creates those and makes the cache ready to accept elements
public void put(Element element) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException
element
-
java.lang.IllegalStateException
- if the cache is not STATUS_ALIVE
java.lang.IllegalArgumentException
- if the element is nullpublic Element get(java.io.Serializable key) throws java.lang.IllegalStateException, CacheException
key
- a serializable value
java.lang.IllegalStateException
- if the cache is not STATUS_ALIVE
CacheException
isExpired(net.sf.ehcache.Element)
public java.util.List getKeys()
public boolean remove(java.io.Serializable key) throws java.lang.IllegalStateException
Element
from the Cache. This also removes it from any
stores it may be in.
key
-
java.lang.IllegalStateException
- if the cache is not STATUS_ALIVE
public void removeAll() throws java.lang.IllegalStateException, java.io.IOException
java.lang.IllegalStateException
- if the cache is not STATUS_ALIVE
java.io.IOException
void dispose() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if the cache is not STATUS_ALIVE
public int getSize() throws java.lang.IllegalStateException
Element
s in the MemoryStore
plus
the number of Element
s in the DiskStore
.
This number is the actual number of elements, including expired elements that have
not been removed.
Expired elements are removed from the the memory store when
getting an expired element, or when attempting to spool an expired element to
disk.
Expired elements are removed from the disk store when getting an expired element,
or when the expiry thread runs, which is once every five minutes.
To get a more accurate number, force expiry by iterating through the getKeys()
list and calling get on each key, before calling this method.
java.lang.IllegalStateException
- if the cache is not STATUS_ALIVE
public int getMemoryStoreSize() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if the cache is not STATUS_ALIVE
public int getDiskStoreSize() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if the cache is not STATUS_ALIVE
public int getStatus()
public int getHitCount() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if the cache is not STATUS_ALIVE
public int getMemoryStoreHitCount() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if the cache is not STATUS_ALIVE
public int getDiskStoreHitCount() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if the cache is not STATUS_ALIVE
public int getMissCountNotFound() throws java.lang.IllegalStateException
getMissCountExpired()
,
or because it was simply not there.
java.lang.IllegalStateException
- if the cache is not STATUS_ALIVE
public int getMissCountExpired() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if the cache is not STATUS_ALIVE
public java.lang.String getName()
void setName(java.lang.String name)
public long getTimeToIdleSeconds()
public long getTimeToLiveSeconds()
public boolean isEternal()
public boolean isOverflowToDisk()
public int getMaxElementsInMemory()
public java.lang.String toString()
String
representation of Cache
public boolean isExpired(Element element) throws java.lang.IllegalStateException, java.lang.NullPointerException
java.lang.IllegalStateException
- if the cache is not STATUS_ALIVE
java.lang.NullPointerException
- if the element is nullpublic java.lang.Object clone() throws java.lang.CloneNotSupportedException
MemoryStore
or DiskStore
has been created.
Cache
java.lang.CloneNotSupportedException
DiskStore getDiskStore() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if the cache is not STATUS_ALIVE
MemoryStore getMemoryStore() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if the cache is not STATUS_ALIVE
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |