Skip to content

Commit 5a308ad

Browse files
committed
Polish MimeTypeUtils LRU cache
This commit improves the cache implementation by skipping the ordering of most recently used cached keys when the cache is at least half empty. See gh-23211
1 parent 511a430 commit 5a308ad

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,13 @@ public ConcurrentLruCache(int maxSize, Function<K, V> generator) {
433433
public V get(K key) {
434434
this.lock.readLock().lock();
435435
try {
436-
if (this.queue.remove(key)) {
436+
if (this.queue.size() < this.maxSize / 2) {
437+
V cached = this.cache.get(key);
438+
if (cached != null) {
439+
return cached;
440+
}
441+
}
442+
else if (this.queue.remove(key)) {
437443
this.queue.add(key);
438444
return this.cache.get(key);
439445
}

0 commit comments

Comments
 (0)