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.HashMapSimple LRU cache for any type of object. Implemented as an extendedHashMapwith a maximum size and an aggregatedListas 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.LinkedListlistLRU list.private intmaxCacheSizeMaximum 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 voidclear()Overrides clear() to also clear the LRU list.private voidfreshenKey(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.Objectget(java.lang.Object key)Overridesget()so that it also updates the LRU list.java.lang.Objectput(java.lang.Object key, java.lang.Object value)Overridesput()so that it also updates the LRU list.java.lang.Objectremove(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:
clearin interfacejava.util.Map- Overrides:
clearin 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:
putin interfacejava.util.Map- Overrides:
putin 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
nullif there was no mapping for key; anullreturn can also indicate that the cache previously associatednullwith 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:
getin interfacejava.util.Map- Overrides:
getin 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
nullif the map contains no mapping for this key
-
remove
public java.lang.Object remove(java.lang.Object key)
- Specified by:
removein interfacejava.util.Map- Overrides:
removein 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
-
-