Interface BasicMultimapCache<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, [email protected]
See Also:
  • Method Details

    • 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 put
      value - the value to added
      Returns:
      CompletableFuture containing a Void
      Since:
      9.2
    • get

      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 containing Boolean.TRUE if the entry was removed, and Boolean.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 removed
      value - value to be removed
      Returns:
      CompletableFuture containing Boolean.TRUE if the key-value pair was removed, and Boolean.FALSE when the key-value pair was not removed
      Since:
      9.2
    • containsKey

      CompletableFuture<Boolean> containsKey(K key)
      Returns Boolean.TRUE if this multimap cache contains the key.
      Parameters:
      key - the key that might exists in this multimap cache
      Returns:
      CompletableFuture containing a Boolean
      Since:
      9.2
    • containsValue

      CompletableFuture<Boolean> containsValue(V value)
      Asynchronous method that returns Boolean.TRUE if this multimap cache contains the value at any key.
      Parameters:
      value - the value that might exists in any entry
      Returns:
      CompletableFuture containing a Boolean
      Since:
      9.2
    • containsEntry

      CompletableFuture<Boolean> containsEntry(K key, V value)
      Returns Boolean.TRUE if this multimap cache contains the key-value pair.
      Parameters:
      key - the key of the key-value pair
      value - the value of the key-value pair
      Returns:
      CompletableFuture containing a Boolean
      Since:
      9.2
    • 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 as Long
      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