File tree Expand file tree Collapse file tree 2 files changed +6
-14
lines changed
spring-context/src/main/java/org/springframework/cache/concurrent
spring-context-support/src/main/java/org/springframework/cache/caffeine Expand file tree Collapse file tree 2 files changed +6
-14
lines changed Original file line number Diff line number Diff line change @@ -189,13 +189,11 @@ public Collection<String> getCacheNames() {
189
189
@ Override
190
190
@ Nullable
191
191
public Cache getCache (String name ) {
192
- if (this .dynamic ) {
193
- Cache cache = this .cacheMap .get (name );
194
- return (cache != null ) ? cache : this .cacheMap .computeIfAbsent (name , this ::createCaffeineCache );
195
- }
196
- else {
197
- return this .cacheMap .get (name );
192
+ Cache cache = this .cacheMap .get (name );
193
+ if (cache == null && this .dynamic ) {
194
+ cache = this .cacheMap .computeIfAbsent (name , this ::createCaffeineCache );
198
195
}
196
+ return cache ;
199
197
}
200
198
201
199
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2021 the original author or authors.
2
+ * Copyright 2002-2023 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -165,13 +165,7 @@ public Collection<String> getCacheNames() {
165
165
public Cache getCache (String name ) {
166
166
Cache cache = this .cacheMap .get (name );
167
167
if (cache == null && this .dynamic ) {
168
- synchronized (this .cacheMap ) {
169
- cache = this .cacheMap .get (name );
170
- if (cache == null ) {
171
- cache = createConcurrentMapCache (name );
172
- this .cacheMap .put (name , cache );
173
- }
174
- }
168
+ cache = this .cacheMap .computeIfAbsent (name , this ::createConcurrentMapCache );
175
169
}
176
170
return cache ;
177
171
}
You can’t perform that action at this time.
0 commit comments