参考 org.apache.kafka.common.cache.LRUCache1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34/**
* Interface for caches, semi-peristent maps which store key-value mappings until either an eviction criteria is met
* or the entries are manually invalidated. Caches are not required to be thread-safe, but some implementations may be.
*/
public interface Cache<K, V> {
/**
* Look up a value in the cache.
* @param key the key to
* @return the cached value, or null if it is not present.
*/
V get(K key);
/**
* Insert an entry into the cache.
* @param key the key to insert
* @param value the value to insert
*/
void put(K key, V value);
/**
* Manually invalidate a key, clearing its entry from the cache.
* @param key the key to remove
* @return true if the key existed in the cache and the entry was removed or false if it was not present
*/
boolean remove(K key);
/**
* Get the number of entries in this cache. If this cache is used by multiple threads concurrently, the returned
* value will only be approximate.
* @return the number of entries in the cache
*/
long size();
}
1 | import java.util.LinkedHashMap; |