Skip to content

Commit

Permalink
issue-2494 : code refectoring
Browse files Browse the repository at this point in the history
  • Loading branch information
nnares committed Jan 27, 2023
1 parent be30a76 commit 374f325
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ class Eh107CacheManager implements CacheManager {

}

private <K, V> Eh107Cache<K, V> wrapEhcacheCache(String alias, CacheConfiguration<K, V> ehConfig) {
org.ehcache.Cache<K, V> cache = ehCacheManager.getCache(alias, ehConfig.getKeyType(), ehConfig.getValueType());
return wrapEhcacheCache(alias, (InternalCache<K, V>)cache);
}

private void loadCache(String cacheName) {
Map<String, CacheConfiguration<?, ?>> cacheConfigurations = ehCacheManager.getRuntimeConfiguration().getCacheConfigurations();
CacheConfiguration<?, ?> cacheConfiguration;
Expand All @@ -103,7 +98,11 @@ private void loadCache(String cacheName) {
}
}
}
}

private <K, V> Eh107Cache<K, V> wrapEhcacheCache(String alias, CacheConfiguration<K, V> ehConfig) {
org.ehcache.Cache<K, V> cache = ehCacheManager.getCache(alias, ehConfig.getKeyType(), ehConfig.getValueType());
return wrapEhcacheCache(alias, (InternalCache<K, V>)cache);
}

private <K, V> Eh107Cache<K, V> wrapEhcacheCache(String alias, InternalCache<K, V> cache) {
Expand Down Expand Up @@ -173,6 +172,7 @@ public <K, V, C extends Configuration<K, V>> Cache<K, V> createCache(String cach
throw new CacheException("A Cache named [" + cacheName + "] already exists");
}
Eh107Cache<K, V> cache = wrapEhcacheCache(cacheName, (InternalCache<K, V>)ehcache);
assert safeCacheRetrieval(cacheName) == null;
lazilyLoadedCaches.put(cacheName, cache);

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -246,6 +246,7 @@ public String toString() {
@Override
public <K, V> Cache<K, V> getCache(String cacheName, Class<K> keyType, Class<V> valueType) {
checkClosed();
loadCache(cacheName);

if (cacheName == null || keyType == null || valueType == null) {
throw new NullPointerException();
Expand Down Expand Up @@ -276,6 +277,7 @@ public <K, V> Cache<K, V> getCache(String cacheName, Class<K> keyType, Class<V>
@Override
public <K, V> Cache<K, V> getCache(String cacheName) {
checkClosed();
loadCache(cacheName);

if (cacheName == null) {
throw new NullPointerException();
Expand All @@ -286,7 +288,6 @@ public <K, V> Cache<K, V> getCache(String cacheName) {

@SuppressWarnings("unchecked")
private <K, V> Eh107Cache<K, V> safeCacheRetrieval(final String cacheName) {
loadCache(cacheName);
final Eh107Cache<?, ?> eh107Cache = lazilyLoadedCaches.get(cacheName);
if(eh107Cache != null && eh107Cache.isClosed()) {
return null;
Expand Down

0 comments on commit 374f325

Please sign in to comment.