public InternalQueryCache < K , V > tryCreateQueryCache ( String mapName , String cacheName , ConstructorFunction < String , InternalQueryCache < K , V > > constructor ) { ContextMutexFactory . Mutex mutex = lifecycleMutexFactory . mutexFor ( mapName ) ; try { synchronized ( mutex ) { ConcurrentMap < String , InternalQueryCache < K , V > > queryCacheRegistry = getOrPutIfAbsent ( queryCacheRegistryPerMap , mapName , queryCacheRegistryConstructor ) ; InternalQueryCache < K , V > queryCache = queryCacheRegistry . get ( cacheName ) ; // if this is a recreation we expect to have a Uuid otherwise we // need to generate one for the first creation of query cache. String cacheId = queryCache == null ? UuidUtil . newUnsecureUuidString ( ) : queryCache . getCacheId ( ) ; queryCache = constructor . createNew ( cacheId ) ; if ( queryCache != NULL_QUERY_CACHE ) { queryCacheRegistry . put ( cacheName , queryCache ) ; return queryCache ; } return null ; } } finally { closeResource ( mutex ) ; } }
Idempotent query cache create mechanism .