org.axonframework.cache
Interface Cache

All Known Implementing Classes:
AbstractCacheAdapter, EhCacheAdapter, JCacheAdapter, NoCache, WeakReferenceCache

public interface Cache

Abstraction for a Caching mechanism. All Axon component rely on this abstraction, so that different providers can be plugged in. In future versions, this abstraction may be replaced with the javax.cache api, as soon as that api is final.

Since:
2.1.2
Author:
Allard Buijze

Nested Class Summary
static interface Cache.EntryListener
          Interface describing callback methods, which are invoked when changes are made in the underlying cache.
static class Cache.EntryListenerAdapter
          Adapter implementation for the EntryListener, allowing for overriding only specific callback methods.
 
Method Summary
<K> boolean
containsKey(K key)
          Indicates whether there is an item stored under given key.
<K,V> V
get(K key)
          Returns an item from the cache, or null if no item was stored under that key
<K,V> void
put(K key, V value)
          Stores the given value in the cache, under given key.
<K,V> boolean
putIfAbsent(K key, V value)
          Stores the given value in the cache, under given key, if no element is yet available under that key.
 void registerCacheEntryListener(Cache.EntryListener cacheEntryListener)
          Registers the given cacheEntryListener to listen for Cache changes.
<K> boolean
remove(K key)
          Removes the entry stored under given key.
 void unregisterCacheEntryListener(Cache.EntryListener cacheEntryListener)
          Unregisters the previously registered cacheEntryListener.
 

Method Detail

get

<K,V> V get(K key)
Returns an item from the cache, or null if no item was stored under that key

Type Parameters:
K - The type of key used
V - The type of value stored
Parameters:
key - The key under which the item was cached
Returns:
the item stored under the given key

put

<K,V> void put(K key,
               V value)
Stores the given value in the cache, under given key. If an item already exists, it is updated with the new value.

Type Parameters:
K - The type of key used
V - The type of value stored
Parameters:
key - The key under which to store the item
value - The item to cache

putIfAbsent

<K,V> boolean putIfAbsent(K key,
                          V value)
Stores the given value in the cache, under given key, if no element is yet available under that key. This operation is performed atomically.

Type Parameters:
K - The type of key used
V - The type of value stored
Parameters:
key - The key under which to store the item
value - The item to cache
Returns:
true if no value was previously assigned to the key, false otherwise.

remove

<K> boolean remove(K key)
Removes the entry stored under given key. If no such entry exists, nothing happens.

Type Parameters:
K - The type of key used
Parameters:
key - The key under which the item was stored
Returns:
true if a value was previously assigned to the key and has been removed, false otherwise.

containsKey

<K> boolean containsKey(K key)
Indicates whether there is an item stored under given key.

Type Parameters:
K - The type of key
Parameters:
key - The key to check
Returns:
true if an item is available under that key, false otherwise.

registerCacheEntryListener

void registerCacheEntryListener(Cache.EntryListener cacheEntryListener)
Registers the given cacheEntryListener to listen for Cache changes.

Parameters:
cacheEntryListener - The listener to register

unregisterCacheEntryListener

void unregisterCacheEntryListener(Cache.EntryListener cacheEntryListener)
Unregisters the previously registered cacheEntryListener.

Parameters:
cacheEntryListener - The listener to unregister


Copyright © 2010-2016. All Rights Reserved.