public class LRUCache
extends java.lang.Object
LinkedHashMap
.
Synthesized and simplified from various published examples of the genre.
The methods are not synchronized.Constructor and Description |
---|
LRUCache(int cacheSize)
Creates a new LRU cache.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clear the cache
|
java.lang.Object |
get(java.lang.Object key)
Retrieves an entry from the cache.
The retrieved entry becomes the most recently used entry. |
void |
put(java.lang.Object key,
java.lang.Object value)
Adds an entry to this cache.
|
public LRUCache(int cacheSize)
cacheSize
- the maximum number of entries that will be kept in this cache.public java.lang.Object get(java.lang.Object key)
key
- the key whose associated value is to be returned.public void put(java.lang.Object key, java.lang.Object 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()