Skip to content

Commit

Permalink
Align ConcurrentMapCacheManager locking behavior with CaffeineCacheMa…
Browse files Browse the repository at this point in the history
…nager

Closes gh-30780
  • Loading branch information
jhoeller committed Jun 30, 2023
1 parent 0c39fff commit 60865ea
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
Expand Up @@ -189,13 +189,11 @@ public Collection<String> getCacheNames() {
@Override
@Nullable
public Cache getCache(String name) {
if (this.dynamic) {
Cache cache = this.cacheMap.get(name);
return (cache != null) ? cache : this.cacheMap.computeIfAbsent(name, this::createCaffeineCache);
}
else {
return this.cacheMap.get(name);
Cache cache = this.cacheMap.get(name);
if (cache == null && this.dynamic) {
cache = this.cacheMap.computeIfAbsent(name, this::createCaffeineCache);
}
return cache;
}


Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -165,13 +165,7 @@ public Collection<String> getCacheNames() {
public Cache getCache(String name) {
Cache cache = this.cacheMap.get(name);
if (cache == null && this.dynamic) {
synchronized (this.cacheMap) {
cache = this.cacheMap.get(name);
if (cache == null) {
cache = createConcurrentMapCache(name);
this.cacheMap.put(name, cache);
}
}
cache = this.cacheMap.computeIfAbsent(name, this::createConcurrentMapCache);
}
return cache;
}
Expand Down

0 comments on commit 60865ea

Please sign in to comment.