Class SimpleLRUCache<K,V>

java.lang.Object
net.sourceforge.jtds.jdbc.cache.SimpleLRUCache<K,V>

public class SimpleLRUCache<K,V> extends Object

Simple LRU cache for any type of object, based on a LinkedHashMap with a maximum size.

Author:
Holger Rehn
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final Map<K,V>
    map backing the LRU cache
  • Constructor Summary

    Constructors
    Constructor
    Description
    SimpleLRUCache(int limit)
    Constructs a new LRU cache with a limited capacity.
  • Method Summary

    Modifier and Type
    Method
    Description
    get(K key)
    Get the value associated with the given key, if any.
    put(K key, V value)
    Updates the LRU cache by adding a new entry.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • _Map

      private final Map<K,V> _Map
      map backing the LRU cache
  • Constructor Details

    • SimpleLRUCache

      public SimpleLRUCache(int limit)

      Constructs a new LRU cache with a limited capacity.

      Parameters:
      limit - maximum number of entries in this cache
  • Method Details

    • put

      public V put(K key, V value)

      Updates the LRU cache by adding a new entry.

      Parameters:
      key - key with which the specified value is to be associated
      value - value to be associated with the specified key
      Returns:
      previous value associated with key or null if there was no mapping for key; a null value can also indicate that the cache previously associated null with the specified key
      See Also:
    • get

      public V get(K key)

      Get the value associated with the given key, if any.

      Parameters:
      key - the key whose associated value is to be returned
      Returns:
      the value to which the specified key is mapped, or null if this map contains no mapping for the key
      See Also: