Package org.infinispan.multimap.api
Interface BasicMultimapCache<K,V>
-
- All Known Subinterfaces:
MultimapCache<K,V>
@Experimental public interface BasicMultimapCache<K,V>
BasicMultimapCache
provides the common API for the two different types of multimap caches that Infinispan provides: embedded and remote.Please see the Infinispan documentation and/or the 5 Minute Usage Tutorial for more details on Infinispan.
MutimapCache is a type of Infinispan Cache that maps keys to values, similar to
AsyncCache
in which each key can contain multiple values.foo → 1 bar → 3, 4, 5
Example
multimapCache.put("k", "v1").join(); multimapCache.put("k", "v2").join(); multimapCache.put("k", "v3").join(); Collection
results = multimapCache.get("k").join(); Eviction
Eviction works per key. This means all the values associated on a key will be evicted.
Views
The returned collections when calling "get" are views of the values on the key. Any change on these collections won't affect the cache values on the key.
Null values
Null values are not supported. The multimap cache won't have a null key or any null value.Example
multimapCache.put(null, "v1").join() → fails multimapCache.put("k", null).join() → fails multimapCache.put("k", "v1").join() → works and add's v1 multimapCache.containsKey("k").join() → true multimapCache.remove("k", "v1").join() → works, removes v1 and as the remaining collection is empty, the key is removed multimapCache.containsKey("k").join() → false
- Since:
- 9.2
- Author:
- Katia Aresti, karesti@redhat.com
- See Also:
- Infinispan documentation
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description CompletableFuture<Boolean>
containsEntry(K key, V value)
ReturnsBoolean.TRUE
if this multimap cache contains the key-value pair.CompletableFuture<Boolean>
containsKey(K key)
ReturnsBoolean.TRUE
if this multimap cache contains the key.CompletableFuture<Boolean>
containsValue(V value)
Asynchronous method that returnsBoolean.TRUE
if this multimap cache contains the value at any key.CompletableFuture<Collection<V>>
get(K key)
Returns a view collection of the values associated with key in this multimap cache, if any.CompletableFuture<Void>
put(K key, V value)
Puts a key-value pair in this multimap cache.CompletableFuture<Boolean>
remove(K key)
Removes all the key-value pairs associated with the key from this multimap cache, if such exists.CompletableFuture<Boolean>
remove(K key, V value)
Removes a key-value pair from this multimap cache, if such exists.CompletableFuture<Long>
size()
Returns the number of key-value pairs in this multimap cache.boolean
supportsDuplicates()
Multimap can support duplicates on the same key k → ['a', 'a', 'b'] or not k → ['a', 'b'] depending on configuration.
-
-
-
Method Detail
-
put
CompletableFuture<Void> put(K key, V value)
Puts a key-value pair in this multimap cache.- If this multimap cache supports duplicates, the value will be always added.
- If this multimap cache does not support duplicates and the value exists on the key, nothing will be done.
- Parameters:
key
- the key to be putvalue
- the value to added- Returns:
CompletableFuture
containing aVoid
- Since:
- 9.2
-
get
CompletableFuture<Collection<V>> get(K key)
Returns a view collection of the values associated with key in this multimap cache, if any. Any changes to the retrieved collection won't change the values in this multimap cache. When this method returns an empty collection, it means the key was not found.- Parameters:
key
- to be retrieved- Returns:
- a
CompletableFuture
containing
which is a view of the underlying values. - Since:
- 9.2
-
remove
CompletableFuture<Boolean> remove(K key)
Removes all the key-value pairs associated with the key from this multimap cache, if such exists.- Parameters:
key
- to be removed- Returns:
- a
CompletableFuture
containingBoolean.TRUE
if the entry was removed, andBoolean.FALSE
when the entry was not removed - Since:
- 9.2
-
remove
CompletableFuture<Boolean> remove(K key, V value)
Removes a key-value pair from this multimap cache, if such exists. Returns true when the key-value pair has been removed from the key.- In the case where duplicates are not supported, only one the key-value pair will be removed, if such exists.
- In the case where duplicates are supported, all the key-value pairs will be removed.
- If the values remaining after the remove call are empty, the whole entry will be removed.
- Parameters:
key
- key to be removedvalue
- value to be removed- Returns:
CompletableFuture
containingBoolean.TRUE
if the key-value pair was removed, andBoolean.FALSE
when the key-value pair was not removed- Since:
- 9.2
-
containsKey
CompletableFuture<Boolean> containsKey(K key)
ReturnsBoolean.TRUE
if this multimap cache contains the key.- Parameters:
key
- the key that might exists in this multimap cache- Returns:
CompletableFuture
containing aBoolean
- Since:
- 9.2
-
containsValue
CompletableFuture<Boolean> containsValue(V value)
Asynchronous method that returnsBoolean.TRUE
if this multimap cache contains the value at any key.- Parameters:
value
- the value that might exists in any entry- Returns:
CompletableFuture
containing aBoolean
- Since:
- 9.2
-
containsEntry
CompletableFuture<Boolean> containsEntry(K key, V value)
ReturnsBoolean.TRUE
if this multimap cache contains the key-value pair.- Parameters:
key
- the key of the key-value pairvalue
- the value of the key-value pair- Returns:
CompletableFuture
containing aBoolean
- Since:
- 9.2
-
size
CompletableFuture<Long> size()
Returns the number of key-value pairs in this multimap cache. It doesn't return the distinct number of keys.This method is blocking in a explicit transaction context.
The
CompletableFuture
is a- Returns:
CompletableFuture
containing the size asLong
- Since:
- 9.2
-
supportsDuplicates
boolean supportsDuplicates()
Multimap can support duplicates on the same key k → ['a', 'a', 'b'] or not k → ['a', 'b'] depending on configuration.Returns duplicates are supported or not in this multimap cache.
- Returns:
true
if this multimap supports duplicate values for a given key.- Since:
- 9.2
-
-