Class LruCache<K,V>
- java.lang.Object
-
- software.amazon.awssdk.utils.cache.lru.LruCache<K,V>
-
@ThreadSafe public final class LruCache<K,V> extends Object
A thread-safe LRU (Least Recently Used) cache implementation that returns the value for a specified key, retrieving it by either getting the stored value from the cache or using a supplied function to calculate that value and add it to the cache.When the cache is full, a new value will push out the least recently used value. When the cache is queried for an already stored value (cache hit), this value is moved to the back of the queue before it's returned so that the order of most recently used to least recently used can be maintained.
The user can configure the maximum size of the cache, which is set to a default of 100.
Null values are accepted.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
LruCache.Builder<K,V>
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <K,V>
LruCache.Builder<K,V>builder(Function<K,V> supplier)
V
get(K key)
Get a value based on the key.int
size()
-
-
-
Method Detail
-
get
public V get(K key)
Get a value based on the key. If the value exists in the cache, it's returned, and it's position in the cache is updated. Otherwise, the value is calculated based on the supplied functionbuilder(Function)
.
-
size
public int size()
-
builder
public static <K,V> LruCache.Builder<K,V> builder(Function<K,V> supplier)
-
-