The goal is to provide Infinispan Native CacheMultimap support. The proposal here is to start with the smallest interface implementation, in order to provide a proper API to the first multimap client, vert-x project. However, this API will evolve, and this first implementation must work on Embedded and Server mode. This first Multimap won’t support duplicate values on the same key.
public interface MultimapCache<K, V> {
void put(K key, V value); // (1)
Collection<V> get(K key); // (2)
boolean remove(K key); //(3)
boolean remove(K key, V value);
void remove(Predicate<V> p); //(4)
}
-
"Put" indicates that the value is being somehow replaced on a key if the key already exists. An alternative could be to call it "add"
-
We might want to return a Set instead of Collection interface, because duplicates on same key won’t be supported yet.
-
Calling this method "reset" has been suggested
-
vert-x implementation needs a way to remove values depending on a given Predicate. To achieve this, we need to provide an API or CacheSet<K> keySet(); method.
An alternative is to support only Async API instead of the standard sync API.
public interface MultimapCache<K, V> {
CompletableFuture<Void> put(K key, V value);
CompletableFuture<Collection<V>> get(K key);
CompletableFuture<Boolean> remove(K key);
CompletableFuture<Boolean> remove(K key, V value);
CompletableFuture<Void> remove(Predicate<V> p);
}
The underlying implementation will wrap a normal Cache. Some of the suggestions :
Apparently there is a problem with functional commands. They don’t really work efficiently over Hot Rod (does get/replace in a loop). We would need to add some more handling in the protocol to allow for only partial replication of values and only 1 remote call.
A new maven module is created.
To create a multimap cache
EmbeddedCacheManager cm = ...
MultimapCacheManager multimapCacheManager = EmbeddedMultimapCacheManagerFactory.from(cm);
multimapCache = multimapCacheManager.get("test");
multimapCache.put("k", "v");
There are at least two options for the implementation
We define a new interface called RemoteMultimapCache that won’t support methods with lambdas, but the most common and useful methods will be supported.
We implement it using the existing OperationsFactory. We enrich the header or we add a flag so the server will know that this call is meant to be over a multimap. So the internal implementation will grab the cache manager and the cache, create the EmbeddedMultimapCache and call the methods over that instance instead of over the regular cache methods.
-
+ Code reuse
-
- Spaghetti code risk