Skip to content

Commit

Permalink
Add cache existence checking before creation (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
denis256 authored Mar 18, 2023
1 parent ea46e8c commit 6206bab
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ Cache integration:
cache:
data:
type: jcache
name: org.ehcache.jsr107.EhcacheCachingProvider
provider: org.ehcache.jsr107.EhcacheCachingProvider
implementationUri: "file://./ehcache.xml"
name: "polydata"
```

## License
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;

/**
* Interface for storage factories
Expand Down Expand Up @@ -49,9 +50,20 @@ default Optional<Cache<String, BasicPoly>> fetchCache(BasicPoly config) {
if (StringUtils.isNotBlank(implementationUri)) {
try {
CacheManager cacheManager = provider.getCacheManager(new URI(implementationUri), null);
Optional<MutableConfiguration<String, BasicPoly>> configuration = fetchJCacheConfig(config);
if (configuration.isPresent()) {
cache = cacheManager.createCache(cacheName, configuration.get());
AtomicBoolean cacheExists = new AtomicBoolean(false);
cacheManager.getCacheNames().iterator().forEachRemaining(name -> {
if (name.equals(cacheName)) {
cacheExists.set(true);
}
});

if (!cacheExists.get()) {
Optional<MutableConfiguration<String, BasicPoly>> configuration = fetchJCacheConfig(config);
if (configuration.isPresent()) {
cache = cacheManager.createCache(cacheName, configuration.get());
} else {
cache = cacheManager.getCache(cacheName);
}
} else {
cache = cacheManager.getCache(cacheName);
}
Expand Down

0 comments on commit 6206bab

Please sign in to comment.