See gh-22340
This commit is contained in:
Brian Clozel
2019-02-05 14:48:17 +01:00
parent ba8849dda3
commit 1bf3b36ce8
2 changed files with 12 additions and 2 deletions

View File

@@ -399,6 +399,16 @@ public abstract class MimeTypeUtils {
return new String(generateMultipartBoundary(), StandardCharsets.US_ASCII);
}
/**
* Simple Least Recently Used cache, bounded by the maximum size given
* to the class constructor.
* This implementation is backed by a {@code ConcurrentHashMap} for storing
* the cached values and a {@code ConcurrentLinkedQueue} for ordering
* the keys and choosing the least recently used key when the cache is at
* full capacity.
* @param <K> the type of the key used for caching
* @param <V> the type of the cached values
*/
static class ConcurrentLRUCache<K, V> {
private final int maxSize;
@@ -418,7 +428,7 @@ public abstract class MimeTypeUtils {
this.generator = generator;
}
public V get(K key) {
V get(K key) {
this.lock.readLock().lock();
try {
if (this.queue.remove(key)) {