public class LRUCache<K,V> extends 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.
|
LRUCache(int cacheSize,
boolean concurrent)
Creates a new LRU cache, with the option of making it thread-safe
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clear the cache
|
V |
get(K key)
Retrieves an entry from the cache.
The retrieved entry becomes the most recently used entry. |
void |
put(K key,
V value)
Adds an entry to this cache.
|
int |
size()
Get the number of entries in the cache
|
public LRUCache(int cacheSize)
cacheSize
- the maximum number of entries that will be kept in this cache.public LRUCache(int cacheSize, boolean concurrent)
cacheSize
- the maximum number of entries that will be kept in this cache.concurrent
- set to true if concurrent access is required, so that access will
be synchronizedpublic 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 size()
Copyright (c) 2004-2013 Saxonica Limited. All rights reserved.