MCPcopy
hub / github.com/apache/kafka / LRUCache

Class LRUCache

clients/src/main/java/org/apache/kafka/common/cache/LRUCache.java:25–56  ·  view source on GitHub ↗

A cache implementing a least recently used policy.

Source from the content-addressed store, hash-verified

23 * A cache implementing a least recently used policy.
24 */
25public class LRUCache<K, V> implements Cache<K, V> {
26 private final LinkedHashMap<K, V> cache;
27
28 public LRUCache(final int maxSize) {
29 cache = new LinkedHashMap<>(16, .75f, true) {
30 @Override
31 protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
32 return this.size() > maxSize; // require this. prefix to make lgtm.com happy
33 }
34 };
35 }
36
37 @Override
38 public V get(K key) {
39 return cache.get(key);
40 }
41
42 @Override
43 public void put(K key, V value) {
44 cache.put(key, value);
45 }
46
47 @Override
48 public boolean remove(K key) {
49 return cache.remove(key) != null;
50 }
51
52 @Override
53 public long size() {
54 return cache.size();
55 }
56}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…