|
ehcache | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.ehcache.jcache.JCache
public class JCache
Warning: This class is related to the JSR107 specification, which is in draft. It is subject to change without notice.
A cache implementation that matches the draft JCACHE specification. WARNING: The JCache specfication is in draft and this API will change up until the time that JCACHE is finalised. It is not possible for one class to implement both JCACHE and Ehcache in the same class due to conflicts with method signatures on get and remove. This implementation is an adaptor to Ehcache, and will exhibit the same underlying characteristics as Ehcache. Additiona features have been added to Ehcache to match the JCache features. All of these features can be configured in ehcache.xml. The current JCache CacheManager class, available in the draft, is considered unworkable. Instead, use the EhcachecacheManager.getJCache(String name)
to get a JCache. The JCache CacheManager is unlikely to make it into the final spec.
The recommended creational pattern for JCache is one of:
cacheManager.getJCache(String name)
to access it.
cacheManager.addCache(JCache jCache)
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface java.util.Map |
---|
java.util.Map.Entry<K,V> |
Constructor Summary | |
---|---|
JCache(Ehcache cache)
A constructor for JCache. |
|
JCache(Ehcache cache,
net.sf.jsr107cache.CacheLoader cacheLoader)
A constructor for JCache. |
|
JCache(Ehcache cache,
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.lang.Object |
get(java.lang.Object key,
CacheLoader loader)
The get method will return, from the cache, the object associated with the argument "key". |
java.lang.Object |
get(java.lang.Object key,
CacheLoader loader,
java.lang.Object loaderArgument)
The get method will return, from the cache, the object associated with the argument "key". |
java.lang.Object |
get(java.lang.Object key,
java.lang.Object loaderArgument)
Same as get(Object) except a CacheLoader argument is provided. |
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". |
java.util.Map |
getAll(java.util.Collection keys,
java.lang.Object loaderArgument)
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. |
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. |
void |
loadAll(java.util.Collection keys,
java.lang.Object argument)
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). |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value,
int timeToLiveSeconds)
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(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)
cache
- An ehcachepublic JCache(Ehcache cache, net.sf.jsr107cache.CacheLoader cacheLoader)
cache
- An ehcachecacheLoader
- used to load entries when they are not in the cache. If this is null, it is
set for the cache. If null, the JCache will inherit the CacheLoader set for the backing ehcache.
If specified, the underlying ehcache will have it's loader replaced.public JCache(Ehcache cache, CacheLoader cacheLoader)
cache
- An ehcachecacheLoader
- used to load entries when they are not in the cache. If this is null, it is
set for the cache. If null, the JCache will inherit the CacheLoader set for the backing ehcache.
If specified, the underlying ehcache will have it's loader replaced.Method Detail |
---|
public void setCacheLoader(CacheLoader cacheLoader)
cacheLoader
- the loader to dynamically load new cache entries. This replaces the CacheLoader in the underlying ehcache.public 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 java.util.Map getAll(java.util.Collection keys, java.lang.Object loaderArgument) 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.
keys
-
net.sf.jsr107cache.CacheException
public 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 void loadAll(java.util.Collection keys, java.lang.Object argument) throws net.sf.jsr107cache.CacheException
SelfPopulatingCache
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.containsKey(Object)
public java.lang.Object get(java.lang.Object key, java.lang.Object loaderArgument) throws java.lang.RuntimeException
get(Object)
except a CacheLoader argument is provided.
key
- key whose associated value is to be returned.loaderArgument
- anything at all that a CacheLoader might find useful to load
the entry. If the loaderArgument is null, this method is the same as get(Object)
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.public java.lang.Object get(java.lang.Object key, CacheLoader loader) throws java.lang.RuntimeException
key
- key whose associated value is to be returned.loader
- A specific CacheLoader to use in place of the default one.
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.containsKey(Object)
public java.lang.Object get(java.lang.Object key, CacheLoader loader, java.lang.Object loaderArgument) throws java.lang.RuntimeException
key
- key whose associated value is to be returned.loader
- A specific CacheLoader to use in place of the default one.loaderArgument
- an Object with acts as a loaderArgument. It can contain anything that makes sense to the loader.
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.containsKey(Object)
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 put(java.lang.Object key, java.lang.Object value, int timeToLiveSeconds)
m.containsKey(k)
would return
true.))
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.timeToLiveSeconds
- the time this entry will live, overriding the default. If timeToLive
is set to 0, the default will be applied.
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 |