|
ehcache]]> | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.ehcache.jcache.JCache
public class JCache
A cache implementation that matches the JCACHE specification.
It is not possible for one class to implement both JCACHE and Ehcache in the same class due to conflicts with method signatures. This implementation is a decorator for Ehcache, and should exhibit the same underlying characteristics as Ehcache. Note that JCACHE contains no lifecyle methods. JCaches cannot be stopped. Any resources, such as loader threads cannot be released, although they will die off after 60 seconds.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface java.util.Map |
---|
java.util.Map.Entry<K,V> |
Constructor Summary | |
---|---|
JCache(Ehcache cache,
net.sf.jsr107cache.CacheLoader cacheLoader)
A constructor for JCache. |
Method Summary | |
---|---|
void |
addListener(net.sf.jsr107cache.CacheListener cacheListener)
Add a listener to the list of cache listeners. |
void |
clear()
Removes all mappings from this map (optional operation). |
boolean |
containsKey(java.lang.Object key)
Returns true if this map contains a mapping for the specified key. |
boolean |
containsValue(java.lang.Object value)
Returns true if this map maps one or more keys to the specified value. |
java.util.Set |
entrySet()
Returns a set view of the mappings contained in this map. |
void |
evict()
The evict method will remove objects from the cache that are no longer valid. |
java.lang.Object |
get(java.lang.Object key)
The get method will return, from the cache, the object associated with the argument "key". |
java.util.Map |
getAll(java.util.Collection keys)
The getAll method will return, from the cache, a Map of the objects associated with the Collection of keys in argument "keys". |
Ehcache |
getBackingCache()
Gets the backing Ehcache |
net.sf.jsr107cache.CacheEntry |
getCacheEntry(java.lang.Object key)
returns the CacheEntry object associated with the key. |
net.sf.jsr107cache.CacheLoader |
getCacheLoader()
Gets the CacheLoader registered in this cache |
net.sf.jsr107cache.CacheStatistics |
getCacheStatistics()
Gets an immutable Statistics object representing the Cache statistics at the time. |
boolean |
isEmpty()
Returns true if this map contains no key-value mappings. |
java.util.Set |
keySet()
Returns a set view of the keys contained in this map. |
void |
load(java.lang.Object key)
The load method provides a means to "pre load" the cache. |
void |
loadAll(java.util.Collection keys)
The loadAll method provides a means to "pre load" objects into the cache. |
java.lang.Object |
peek(java.lang.Object key)
The peek method will return the object associated with "key" if it currently exists (and is valid) in the cache. |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Associates the specified value with the specified key in this map (optional operation). |
void |
putAll(java.util.Map sourceMap)
Copies all of the mappings from the specified map to this map (optional operation). |
java.lang.Object |
remove(java.lang.Object key)
Removes the mapping for this key from this map if it is present (optional operation). |
void |
removeListener(net.sf.jsr107cache.CacheListener cacheListener)
Remove a listener from the list of cache listeners |
void |
setCacheLoader(net.sf.jsr107cache.CacheLoader cacheLoader)
Setter for the CacheLoader. |
void |
setStatisticsAccuracy(int statisticsAccuracy)
Sets the statistics accuracy. |
int |
size()
Returns the number of key-value mappings in this map. |
java.lang.String |
toString()
Returns a String representation of the underlying Cache . |
java.util.Collection |
values()
Returns a collection view of the values contained in this map. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface net.sf.jsr107cache.Cache |
---|
equals, hashCode |
Constructor Detail |
---|
public JCache(Ehcache cache, net.sf.jsr107cache.CacheLoader cacheLoader)
ConfigurationFactory
and clients can create these.
A client can specify their own settings here and pass the Ehcache
object
into CacheManager.addCache(java.lang.String)
to specify parameters other than the defaults.
Only the CacheManager can initialise them.
cache
- An ehcachecacheLoader
- used to load entries when they are not in the cache. If this is null,
which is legal, loads do a noopMethod Detail |
---|
public void setCacheLoader(net.sf.jsr107cache.CacheLoader cacheLoader)
cacheLoader
- the loader to dynamically load new cache entriespublic void addListener(net.sf.jsr107cache.CacheListener cacheListener)
JCacheListenerAdaptor
for details on how each event is adapted.
addListener
in interface net.sf.jsr107cache.Cache
cacheListener
- a JCACHE CacheListenerJCacheListenerAdaptor
public void evict()
evict
in interface net.sf.jsr107cache.Cache
public java.util.Map getAll(java.util.Collection keys) throws net.sf.jsr107cache.CacheException
SelfPopulatingCache
Note. If the getAll exceeds the maximum cache
size, the returned map will necessarily be less than the number specified.
getAll
in interface net.sf.jsr107cache.Cache
keys
-
net.sf.jsr107cache.CacheException
public net.sf.jsr107cache.CacheLoader getCacheLoader()
public net.sf.jsr107cache.CacheEntry getCacheEntry(java.lang.Object key)
getCacheEntry
in interface net.sf.jsr107cache.Cache
key
- the key to look for in the cachepublic net.sf.jsr107cache.CacheStatistics getCacheStatistics() throws java.lang.IllegalStateException
CacheStatistics.STATISTICS_ACCURACY_BEST_EFFORT
.
The size is the number of 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. Any duplicates between stores are accounted for.
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.
CacheStatistics.STATISTICS_ACCURACY_GUARANTEED
.
This method accounts for elements which might be expired or duplicated between stores. It take approximately
200ms per 1000 elements to execute.
CacheStatistics.STATISTICS_ACCURACY_NONE
.
The number given may contain expired elements. In addition if the DiskStore is used it may contain some double
counting of elements. It takes 6ms for 1000 elements to execute. Time to execute is O(log n). 50,000 elements take
36ms.
getCacheStatistics
in interface net.sf.jsr107cache.Cache
java.lang.IllegalStateException
- if the cache is not Status.STATUS_ALIVE
public void load(java.lang.Object key) throws net.sf.jsr107cache.CacheException
SelfPopulatingCache
load
in interface net.sf.jsr107cache.Cache
key
- key whose associated value to be loaded using the associated cacheloader if this cache doesn't contain it.
net.sf.jsr107cache.CacheException
public void loadAll(java.util.Collection keys) throws net.sf.jsr107cache.CacheException
SelfPopulatingCache
loadAll
in interface net.sf.jsr107cache.Cache
net.sf.jsr107cache.CacheException
public java.lang.Object peek(java.lang.Object key)
get(java.lang.Object)
peek
in interface net.sf.jsr107cache.Cache
key
-
public void removeListener(net.sf.jsr107cache.CacheListener cacheListener)
removeListener
in interface net.sf.jsr107cache.Cache
cacheListener
- a JCACHE CacheListenerJCacheListenerAdaptor
public int size()
size
in interface java.util.Map
size
in interface net.sf.jsr107cache.Cache
public boolean isEmpty()
isEmpty
in interface java.util.Map
isEmpty
in interface net.sf.jsr107cache.Cache
public boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map
containsKey
in interface net.sf.jsr107cache.Cache
key
- key whose presence in this map is to be tested.
public boolean containsValue(java.lang.Object value)
containsValue
in interface java.util.Map
containsValue
in interface net.sf.jsr107cache.Cache
value
- value whose presence in this map is to be tested.
public java.lang.Object get(java.lang.Object key) throws java.lang.RuntimeException
get
in interface java.util.Map
get
in interface net.sf.jsr107cache.Cache
key
- key whose associated value is to be returned.
java.lang.RuntimeException
- JSR107 should really throw a CacheException here, but the
spec does not allow it. Instead throw a RuntimeException if the underlying load method
throws a CacheException.todo consider removing async stuff
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
m.containsKey(k)
would return
true.))
put
in interface java.util.Map
put
in interface net.sf.jsr107cache.Cache
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.
public java.lang.Object remove(java.lang.Object key)
(key==null ? k==null : key.equals(k))
, that mapping
is removed. (The map can contain at most one such mapping.)
Returns the value to which the map previously associated the key, or null if the map contained no mapping for this key. (A null return can also indicate that the map previously associated null with the specified key if the implementation supports null values.) The map will not contain a mapping for the specified key once the call returns.
remove
in interface java.util.Map
remove
in interface net.sf.jsr107cache.Cache
key
- key whose mapping is to be removed from the map.
public void putAll(java.util.Map sourceMap)
put(k, v)
on this map once
for each mapping from key k to value v in the
N specified map. The behavior of this operation is unspecified if the
specified map is modified while the operation is in progress.
putAll
in interface java.util.Map
putAll
in interface net.sf.jsr107cache.Cache
sourceMap
- Mappings to be stored in this map.public void clear()
clear
in interface java.util.Map
clear
in interface net.sf.jsr107cache.Cache
public java.util.Set keySet()
keySet
in interface java.util.Map
keySet
in interface net.sf.jsr107cache.Cache
public java.util.Collection values()
values
in interface java.util.Map
values
in interface net.sf.jsr107cache.Cache
public java.util.Set entrySet()
Map.Entry
. The set is backed by the
map, so changes to the map are reflected in the set, and vice-versa.
If the map is modified while an iteration over the set is in progress
(except through the iterator's own remove operation, or through
the setValue operation on a map entry returned by the iterator)
the results of the iteration are undefined. The set supports element
removal, which removes the corresponding mapping from the map, via the
Iterator.remove, Set.remove, removeAll,
retainAll and clear operations. It does not support
the add or addAll operations.
Contradicting the above Map contract, whether or not changes to an entry affect the entry in the cache is undefined.
entrySet
in interface java.util.Map
entrySet
in interface net.sf.jsr107cache.Cache
public void setStatisticsAccuracy(int statisticsAccuracy)
statisticsAccuracy
- one of CacheStatistics.STATISTICS_ACCURACY_BEST_EFFORT
, CacheStatistics.STATISTICS_ACCURACY_GUARANTEED
, CacheStatistics.STATISTICS_ACCURACY_NONE
public Ehcache getBackingCache()
public java.lang.String toString()
String
representation of the underlying Cache
.
toString
in class java.lang.Object
|
ehcache]]> | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |