Skip to content

Commit

Permalink
Caching provider cache (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
denis256 authored Apr 21, 2024
1 parent cef1b2d commit 87087dd
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import javax.cache.spi.CachingProvider;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;

Expand All @@ -27,6 +29,7 @@ static Optional<MutableConfiguration<String, BasicPoly>> fetchJCacheConfig(Basic
return Optional.of(jcacheConfig);
}

protected Map<String, CachingProvider> cachingProviders = new HashMap<>();
/**
* Fetch cache provider from configuration
*/
Expand All @@ -45,7 +48,18 @@ public Optional<Cache<String, BasicPoly>> fetchCache(BasicPoly config) {
if (StringUtils.isBlank(cacheProvider)) {
provider = Caching.getCachingProvider();
} else {
provider = Caching.getCachingProvider(cacheProvider);
provider = cachingProviders.computeIfAbsent(cacheProvider, key -> {
try {
return Caching.getCachingProvider(cacheProvider);
} catch (Exception e) {
log.error("Failed to get caching provider {}", cacheProvider, e);
return null;
}
});
if (provider == null) {
log.error("Failed to get caching provider {}", cacheProvider);
return Optional.empty();
}
}

Cache<String, BasicPoly> cache = null;
Expand Down

0 comments on commit 87087dd

Please sign in to comment.