public class LRUCache<K,V> extends Object
LinkedHashMap.
This cache has a fixed maximum number of elements (cacheSize).
If the cache is full and another entry is added, the LRU (least recently
used) entry is dropped.
This class is thread-safe. All methods of this class are synchronized.
Author: Christian d'Heureuse, Inventec Informatik AG, Zurich, Switzerland
Multi-licensed: EPL / LGPL / GPL / AL / BSD.
| 构造器和说明 |
|---|
LRUCache(int cacheSize)
Creates a new LRU cache.
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
clear()
Clears the cache.
|
V |
get(K key)
Retrieves an entry from the cache.
|
Collection<Map.Entry<K,V>> |
getAll()
Returns a
Collection that contains a copy of all cache
entries. |
List<V> |
getValues() |
void |
put(K key,
V value)
Adds an entry to this cache.
|
int |
usedEntries()
Returns the number of used entries in the cache.
|
public LRUCache(int cacheSize)
cacheSize - the maximum number of entries that will be kept in this cache.public V get(K key)
key - the key whose associated value is to be returned.public void put(K key, V value)
key - the key with which the specified value is to be associated.value - a value to be associated with the specified key.public void clear()
public int usedEntries()
public Collection<Map.Entry<K,V>> getAll()
Collection that contains a copy of all cache
entries.Collection with a copy of the cache content.Copyright © 2017. All rights reserved.