Package net.sourceforge.jtds.jdbc.cache
Class SimpleLRUCache
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap
-
- net.sourceforge.jtds.jdbc.cache.SimpleLRUCache
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.util.Map
public class SimpleLRUCache extends java.util.HashMap
Simple LRU cache for any type of object. Implemented as an extendedHashMap
with a maximum size and an aggregatedList
as LRU queue.- Version:
- $Id: SimpleLRUCache.java,v 1.1 2005/04/25 11:46:56 alin_sinpalean Exp $
- Author:
- Brett Wooldridge
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.LinkedList
list
LRU list.private int
maxCacheSize
Maximum cache size.
-
Constructor Summary
Constructors Constructor Description SimpleLRUCache(int maxCacheSize)
Constructs a new LRU cache instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Overrides clear() to also clear the LRU list.private void
freshenKey(java.lang.Object key)
Moves the specified value to the top of the LRU list (the bottom of the list is where least recently used items live).java.lang.Object
get(java.lang.Object key)
Overridesget()
so that it also updates the LRU list.java.lang.Object
put(java.lang.Object key, java.lang.Object value)
Overridesput()
so that it also updates the LRU list.java.lang.Object
remove(java.lang.Object key)
-
Methods inherited from class java.util.HashMap
clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, getOrDefault, isEmpty, keySet, merge, putAll, putIfAbsent, remove, replace, replace, replaceAll, size, values
-
-
-
-
Method Detail
-
clear
public void clear()
Overrides clear() to also clear the LRU list.- Specified by:
clear
in interfacejava.util.Map
- Overrides:
clear
in classjava.util.HashMap
-
put
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
Overridesput()
so that it also updates the LRU list.- Specified by:
put
in interfacejava.util.Map
- Overrides:
put
in classjava.util.HashMap
- Parameters:
key
- key with which the specified value is to be associatedvalue
- value to be associated with the key- Returns:
- previous value associated with key or
null
if there was no mapping for key; anull
return can also indicate that the cache previously associatednull
with the specified key - See Also:
Map.put(Object, Object)
-
get
public java.lang.Object get(java.lang.Object key)
Overridesget()
so that it also updates the LRU list.- Specified by:
get
in interfacejava.util.Map
- Overrides:
get
in classjava.util.HashMap
- Parameters:
key
- key with which the expected value is associated- Returns:
- the value to which the cache maps the specified key, or
null
if the map contains no mapping for this key
-
remove
public java.lang.Object remove(java.lang.Object key)
- Specified by:
remove
in interfacejava.util.Map
- Overrides:
remove
in classjava.util.HashMap
- See Also:
Map.remove(Object)
-
freshenKey
private void freshenKey(java.lang.Object key)
Moves the specified value to the top of the LRU list (the bottom of the list is where least recently used items live).- Parameters:
key
- key of the value to move to the top of the list
-
-