public static <K extends Serializable, V, C extends Collection<V> & Serializable> void addValueToMultiValuedCache( Cache<K, C> cache, K key, V element, Supplier<C> supplier )
    {
        final Lock lock = cache.getLock(key);
        lock.lock();
        try
        {
            final C elements = cache.getOrDefault( key, supplier.get() );
            elements.add( element );
            cache.put( key, elements ); // Explicitly adding the value is required for the change to propagate through Hazelcast.
        }
        finally
        {
            lock.unlock();
        }
    }
Adds the specified element to a cache, in a collection that is mapped by the provided key.

When the cache does not contain an entry for the provided key, a cache entry is added, which will have a new collection
created using the provided Supplier, to which the specified element is added.

The implementation of this method is designed to be compatible with both clustered as well as non-clustered caches.

@param cache    The cache from which to remove the element (cannot be null).
@param element  The element to be added (can be null only if the value-Collection supports null values).
@param key      The cache entry identifier (cannot be null)
@param <K> the type of key contained by the cache
@param <V> the type of value contained by the cache
@param <C> the type of collection contained by the cache
@param supplier A provider of empty instances of the collection used as a value of the cache (in which elements are placed).
xmppserver/src/main/java/org/jivesoftware/util/cache/CacheUtil.java