Infinispan implements the semantics of the JDK ConcurrentHashMap. It seems to me like what you want is putIfAbsent which is present in both RemoteCache and in JCache.
what I need is a little different.
I want to invoke the get(String key) method on the javax.cache.Cache interface (configured with setReadThrough(true) and use a custom CacheLoader<String, String>) from two (or more) different concurrent threads for a key not already cached.
When the first thread invokes the load(String key) method on my CacheLoader (configured with setCacheLoaderFactory(new FactoryBuilder.SingletonFactory<CacheLoader<String, String>>(new JCacheCacheLoader())) I want the others threads blocked on the javax.cache.get() method, waiting for the result retrieved from the first CacheLoader.
This because the operation to retrieve the cache value on the CacheLoader is very expansive, and the result will be the same for the same key.
Is it possibile not to execute the others CacheLoader if the first returns correctly?
No, such feature is not natively available, it's tracked as [ISPN-7224] Support synchronous get in Spring's cache abstraction Currently the closest thing you can do is pessimistic transactional cache and issue the read with cache.withFlags(Flag.FORCE_WRITE_LOCK).get(key).
Thank you for your response,
The only way to enable the pessimistic transactional cache is to reconfigure the cache on the remote server?
Is it possible to set the FORCE_WITH_LOCK flag with the JCache API?
Regrettably not, not with JCache, and not even if you're using Hot Rod or REST (as you speak about remote server).
Actually I think that implementing that would be a doable for a new contributor; the changes could be isolated to single interceptor/extending the current CacheLoaderInterceptor.