Cache is a Map-like data structure that provides temporary storage
of application data.
EntryIterablenull
will result in a NullPointerExceptionCacheLoader (read-through-caching)
when a value being requested is not in a cacheCacheWriter (write-through-caching)
when a value being created/updated/removed from a cacheA simple example of how to use a cache is:
String cacheName = "sampleCache";
CachingProvider provider = Caching.getCachingProvider();
CacheManager manager = provider.getCacheManager();
Cache<Integer, Date> cache = manager.getCache(cacheName, Integer.class,
Date.class);
Date value1 = new Date();
Integer key = 1;
cache.put(key, value1);
Date value2 = cache.get(key);
| Modifier and Type | Class and Description |
|---|---|
| public static interface |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public void | close()
Redeclares java. Cache signals to the CacheManager that produced or
owns the Cache that it should no longer be managed.
|
| public boolean | Returns: true if this map contains a mapping for the specified keykey whose presence in this cache is to be tested. key)Determines if the |
| public void | deregisterCacheEntryListener(CacheEntryListenerConfiguration<K, V>
the factory and related configuration
that was used to create the
listener cacheEntryListenerConfiguration)Deregisters a listener, using the
|
| public V | Returns: the element, or null, if it does not exist.the key whose associated value is to be returned key)Gets an entry from the cache. |
| public Map | Returns: A map of entries that were found for the given keys. Keys not found in the cache are not in the returned map.The keys whose associated values are to be returned. keys)Gets a collection of entries from the |
| public V | Returns: the value associated with the key at the start of the operation or null if none was associatedkey with which the specified value is to be associated key, V value to be associated with the specified key value)Associates the specified value with the specified key in this cache, returning an existing value if one existed. |
| public V | Returns: the value if one existed or null if no mapping existed for this keykey with which the specified value is associated key)Atomically removes the entry for a key only if currently mapped to some value. |
| public V | Returns: the previous value associated with the specified key, or null if there was no mapping for the key.key with which the specified value is associated key, V value to be associated with the specified key value)Atomically replaces the value for a given key if and only if there is a value currently mapped by the key. |
| public CacheManager | |
| public < the type of the Configuration C extends Configuration | Returns: the requested implementation ofConfigurationthe configuration interface or class to return. This includes
clazz)Configuration.class and
javax.cache.configuration.CompleteConfigurations.Provides a standard way to access the configuration of a cache using JCache configuration or additional proprietary configuration. |
| public String | |
| public < the type of the return value T> T | Returns: the result of the processing, if any, defined by theEntryProcessor implementationthe key to the entry key, EntryProcessor<K, V, T> the entryProcessor, Object... EntryProcessor to invokeadditional arguments to pass to the
arguments)EntryProcessorInvokes an |
| public < the type of the return value T> Map | Returns: the map ofEntryProcessorResults of the processing per key,
if any, defined by the EntryProcessor implementation. No mappings
will be returned for EntryProcessors that return a
null value for a key.the set of keys for entries to process keys, EntryProcessor<K, V, T> the entryProcessor, Object... EntryProcessor to invokeadditional arguments to pass to the
arguments)EntryProcessorInvokes an |
| public boolean | Returns: true if this Cache instance is closed; false if it is still openDetermines whether this Cache instance has been closed. |
| public Iterator | |
| public void | loadAll(Set<? extends K>
the keys to load keys, boolean when true existing values in the Cache will
be replaced by those loaded from a CacheLoader replaceExistingValues, CompletionListener the CompletionListener (may be null) completionListener)Asynchronously loads the specified entries into the cache using the
configured |
| public void | put(K
key with which the specified value is to be associated key, V value to be associated with the specified key value)Associates the specified value with the specified key in the cache. |
| public void | |
| public boolean | Returns: true if a value was set.key with which the specified value is to be associated key, V value to be associated with the specified key value)Atomically associates the specified key with the given value if it is not already associated with a value. |
| public void | registerCacheEntryListener(CacheEntryListenerConfiguration<K, V>
a factory and related configuration
for creating the listener cacheEntryListenerConfiguration)Registers a |
| public boolean | Returns: returns false if there was no matching keykey whose mapping is to be removed from the cache key)Removes the mapping for a key from this cache if it is present. |
| public boolean | Returns: returns false if there was no matching keykey whose mapping is to be removed from the cache key, V value expected to be associated with the specified key oldValue)Atomically removes the mapping for a key only if currently mapped to the given value. |
| public void | |
| public void | |
| public boolean | Returns: true if the value was replacedkey with which the specified value is associated key, V value expected to be associated with the specified key oldValue, V value to be associated with the specified key newValue)Atomically replaces the entry for a key only if currently mapped to a given value. |
| public boolean | Returns: true if the value was replacedthe key with which the specified value is associated key, V the value to be associated with the specified key value)Atomically replaces the entry for a key only if currently mapped to some value. |
| public < the type of the underlying T> TCache implementation | Returns: an instance of the underlying concrete cachethe proprietary class or interface of the underlying concrete
cache. It is this type that is returned. clazz)Provides a standard way to access the underlying concrete caching implementation to provide access to further, proprietary features. |
| clear | back to summary |
|---|---|
| public void clear() Clears the contents of the cache, without notifying listeners or
| |
| close | back to summary |
|---|---|
| public void close() Redeclares java. Closing a
IllegalStateException.
Closing a Cache does not necessarily destroy the contents of a Cache. It simply signals to the owning CacheManager that the Cache is no longer required by the application and that future uses of a specific Cache instance should not be permitted. Depending on the implementation and Cache topology, (e.g. a storage-backed or distributed cache), the contents of a closed Cache may still be available and accessible by other applications, or, in fact, via the Cache Manager that previously owned the Cache, if an application calls getCache at some point in the future.
| |
| containsKey | back to summary |
|---|---|
| public boolean containsKey(K key) Determines if the More formally, returns true if and only if this cache contains a mapping for a key k such that key.equals(k). (There can be at most one such mapping.)
If the cache is configured read-through the associated
| |
| deregisterCacheEntryListener | back to summary |
|---|---|
| public void deregisterCacheEntryListener(CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) Deregisters a listener, using the
Both listeners registered at configuration time,
and those created at runtime with
| |
| get | back to summary |
|---|---|
| public V get(K key) Gets an entry from the cache.
If the cache is configured to use read-through, and get would return null
because the entry is missing from the cache, the Cache's
| |
| getAll | back to summary |
|---|---|
| public Map Gets a collection of entries from the
If the cache is configured read-through, and a get for a key would
return null because an entry is missing from the cache, the Cache's
| |
| getAndPut | back to summary |
|---|---|
| public V getAndPut(K key, V value) Associates the specified value with the specified key in this cache, returning an existing value if one existed.
If the cache previously contained a mapping for
the key, the old value is replaced by the specified value. (A cache
c is said to contain a mapping for a key k if and only
if The previous value is returned, or null if there was no value associated with the key previously.
If the cache is configured write-through the associated
| |
| getAndRemove | back to summary |
|---|---|
| public V getAndRemove(K key) Atomically removes the entry for a key only if currently mapped to some value. This is equivalent to:
except that the action is performed atomically.
If the cache is configured write-through the associated
| |
| getAndReplace | back to summary |
|---|---|
| public V getAndReplace(K key, V value) Atomically replaces the value for a given key if and only if there is a value currently mapped by the key. This is equivalent to
except that the action is performed atomically.
If the cache is configured write-through, and this method returns true,
the associated
| |
| getCacheManager | back to summary |
|---|---|
| public CacheManager getCacheManager() Gets the
| |
| getConfiguration | back to summary |
|---|---|
| public <C extends Configuration Provides a standard way to access the configuration of a cache using JCache configuration or additional proprietary configuration. The returned value must be immutable.
If the provider's implementation does not support the specified class,
the
| |
| getName | back to summary |
|---|---|
| public String getName() Return the name of the cache.
| |
| invoke | back to summary |
|---|---|
| public <T> T invoke(K key, EntryProcessor<K, V, T> entryProcessor, Object... arguments) throws EntryProcessorException Invokes an
| |
| invokeAll | back to summary |
|---|---|
| public <T> Map Invokes an
The order that the entries for the keys are processed is undefined.
Implementations may choose to process the entries in any order, including
concurrently. Furthermore there is no guarantee implementations will
use the same
The result of executing the
| |
| isClosed | back to summary |
|---|---|
| public boolean isClosed() Determines whether this Cache instance has been closed. A Cache is considered closed if;
This method generally cannot be called to determine whether a Cache instance is valid or invalid. A typical client can determine that a Cache is invalid by catching any exceptions that might be thrown when an operation is attempted.
| |
| iterator | back to summary |
|---|---|
| public Iterator Redeclares java. Doc from java. Returns an iterator over elements of type The ordering of iteration over entries is undefined. During iteration, any entries that are removed will have their appropriate CacheEntryRemovedListeners notified.
When iterating over a cache it must be assumed that the underlying
cache may be changing, with entries being added, removed, evicted
and expiring.
| |
| loadAll | back to summary |
|---|---|
| public void loadAll(Set<? extends K> keys, boolean replaceExistingValues, CompletionListener completionListener) Asynchronously loads the specified entries into the cache using the
configured
If an entry for a key already exists in the Cache, a value will be loaded
if and only if
Implementations may choose to load multiple keys from the provided
The thread on which the completion listener is called is implementation dependent. An implementation may also choose to serialize calls to different CompletionListeners rather than use a thread per CompletionListener.
| |
| put | back to summary |
|---|---|
| public void put(K key, V value) Associates the specified value with the specified key in the cache.
If the
If the cache is configured write-through the
| |
| putAll | back to summary |
|---|---|
| public void putAll(Map<? extends K, ? extends V> map) Copies all of the entries from the specified map to the
The effect of this call is equivalent to that of calling
The order in which the individual puts occur is undefined. The behavior of this operation is undefined if entries in the cache corresponding to entries in the map are modified or removed while this operation is in progress. or if map is modified while the operation is in progress. In Default Consistency mode, individual puts occur atomically but not the entire putAll. Listeners may observe individual updates.
If the cache is configured write-through the associated
| |
| putIfAbsent | back to summary |
|---|---|
| public boolean putIfAbsent(K key, V value) Atomically associates the specified key with the given value if it is not already associated with a value. This is equivalent to:
except that the action is performed atomically.
If the cache is configured write-through, and this method returns true,
the associated
| |
| registerCacheEntryListener | back to summary |
|---|---|
| public void registerCacheEntryListener(CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) Registers a
| |
| remove | back to summary |
|---|---|
| public boolean remove(K key) Removes the mapping for a key from this cache if it is present.
More formally, if this cache contains a mapping from key k to
value v such that
Returns true if this cache previously associated the key, or false if the cache contained no mapping for the key. The cache will not contain a mapping for the specified key once the call returns.
If the cache is configured write-through the associated
| |
| remove | back to summary |
|---|---|
| public boolean remove(K key, V oldValue) Atomically removes the mapping for a key only if currently mapped to the given value. This is equivalent to:
except that the action is performed atomically.
If the cache is configured write-through, and this method returns true,
the associated
| |
| removeAll | back to summary |
|---|---|
| public void removeAll(Set<? extends K> keys) Removes entries for the specified keys. The order in which the individual entries are removed is undefined. For every entry in the key set, the following are called:
| |
| removeAll | back to summary |
|---|---|
| public void removeAll() Removes all of the mappings from this cache. The order that the individual entries are removed is undefined. For every mapping that exists the following are called:
CacheWriter is not called.
This is potentially an expensive operation as listeners are invoked.
Use
| |
| replace | back to summary |
|---|---|
| public boolean replace(K key, V oldValue, V newValue) Atomically replaces the entry for a key only if currently mapped to a given value. This is equivalent to:
except that the action is performed atomically.
If the cache is configured write-through, and this method returns true,
the associated
| |
| replace | back to summary |
|---|---|
| public boolean replace(K key, V value) Atomically replaces the entry for a key only if currently mapped to some value. This is equivalent to
except that the action is performed atomically.
If the cache is configured write-through, and this method returns true,
the associated
| |
| unwrap | back to summary |
|---|---|
| public <T> T unwrap(Class<T> clazz) Provides a standard way to access the underlying concrete caching implementation to provide access to further, proprietary features.
If the provider's implementation does not support the specified class,
the
| |
| Modifier and Type | Method and Description |
|---|---|
| public K | |
| public V | Returns: the value corresponding to this entryReturns the value stored in the cache when this entry was created. |
| public < the type of the underlying T> TEntry implementation | Returns: an instance of the underlying concrete cachethe proprietary class or interface of the underlying
concrete cache. It is this type that is returned. clazz)Provides a standard way to access the underlying concrete cache entry implementation in order to provide access to further, proprietary features. |
| getKey | back to summary |
|---|---|
| public K getKey() Returns the key corresponding to this entry.
| |
| getValue | back to summary |
|---|---|
| public V getValue() Returns the value stored in the cache when this entry was created.
| |
| unwrap | back to summary |
|---|---|
| public <T> T unwrap(Class<T> clazz) Provides a standard way to access the underlying concrete cache entry implementation in order to provide access to further, proprietary features.
If the provider's implementation does not support the specified class,
the
| |