net.sourceforge.jtds.jdbc.cache
Class SimpleLRUCache
java.lang.Object
   java.util.AbstractMap
java.util.AbstractMap
       java.util.HashMap
java.util.HashMap
           net.sourceforge.jtds.jdbc.cache.SimpleLRUCache
net.sourceforge.jtds.jdbc.cache.SimpleLRUCache
- All Implemented Interfaces: 
- java.lang.Cloneable, java.util.Map, java.io.Serializable
- public class SimpleLRUCache- extends java.util.HashMap
Simple LRU cache for any type of object. Implemented as an extended
 HashMap with a maximum size and an aggregated List
 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
 
| Nested classes inherited from class java.util.HashMap | 
|  | 
 
| Nested classes inherited from class java.util.AbstractMap | 
|  | 
 
| Field Summary | 
| private  java.util.LinkedList | listLRU list.
 | 
| private  int | maxCacheSizeMaximum cache size.
 | 
 
| Fields inherited from class java.util.HashMap | 
|  | 
 
| Fields inherited from class java.util.AbstractMap | 
|  | 
 
| Constructor Summary | 
| SimpleLRUCache(int maxCacheSize)Constructs a new LRU cache instance.
 | 
 
| Method Summary | 
|  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)Overrides
 get()so that it also updates the LRU list. | 
|  java.lang.Object | put(java.lang.Object key,
    java.lang.Object value)Overrides
 put()so that it also updates the LRU list. | 
|  java.lang.Object | remove(java.lang.Object key)
 | 
 
| Methods inherited from class java.util.HashMap | 
| clone, containsKey, containsValue, entrySet, isEmpty, keySet, putAll, size, values | 
 
| Methods inherited from class java.util.AbstractMap | 
| equals, hashCode, toString | 
 
| Methods inherited from class java.lang.Object | 
| finalize, getClass, notify, notifyAll, wait, wait, wait | 
 
| Methods inherited from interface java.util.Map | 
| equals, hashCode | 
 
maxCacheSize
private final int maxCacheSize
- Maximum cache size.
 
 
list
private final java.util.LinkedList list
- LRU list.
 
 
SimpleLRUCache
public SimpleLRUCache(int maxCacheSize)
- Constructs a new LRU cache instance.
 
- Parameters:
- maxCacheSize- the maximum number of entries in this cache before
                     entries are aged off
clear
public void clear()
- Overrides clear() to also clear the LRU list.
 
- 
 
put
public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
- Overrides put()so that it also updates the LRU list.
 
- 
- Parameters:
- key- key with which the specified value is to be associated
- value- 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)
- Overrides get()so that it also updates the LRU list.
 
- 
- 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)
- 
- 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
 
Generated on December 30 2009