Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## net.sourceforge.jtds.jdbc.cache
Class SimpleLRUCache

    java.lang.Object
      |
      +--java.util.AbstractMap
            |
            +--java.util.HashMap
                  |
                  +--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

Inner classes inherited from class java.util.Map
`java.util.Map.Entry`

Field Summary
`private java.util.LinkedList` | `list` LRU list.
`private int` | `maxCacheSize` Maximum cache size.

Fields inherited from class java.util.HashMap
`count, emptyHashIterator, ENTRIES, entrySet, KEYS, keySet, loadFactor, modCount, serialVersionUID, table, threshold, values, VALUES`

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
`, capacity, clone, containsKey, containsValue, entrySet, getHashIterator, isEmpty, keySet, loadFactor, putAll, readObject, rehash, size, values, writeObject`

Methods inherited from class java.util.AbstractMap
`equals, hashCode, toString`

Methods inherited from class java.lang.Object
`finalize, getClass, notify, notifyAll, registerNatives, wait, wait, wait`

Methods inherited from interface java.util.Map
`equals, hashCode`

Field Detail

### maxCacheSize

    private final int maxCacheSize

  Maximum cache size.

### list

    private final java.util.LinkedList list

  LRU list.

Constructor Detail

### 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

Method Detail

### clear

    public void clear()

  Overrides clear() to also clear the LRU list.
  Overrides:
    `clear` in class `java.util.HashMap`

### put

    public java.lang.Object put(java.lang.Object key,
                                java.lang.Object value)

  Overrides `put()` so that it also updates the LRU list.
  Overrides:
    `put` in class `java.util.HashMap`
  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 `null` if there was no mapping for key; a `null` return can also indicate that the cache previously associated `null` with 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.
  Overrides:
    `get` in class `java.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)

  Overrides:
    `remove` in class `java.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

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Generated on August 22 2007