Class LRUCache<K,V>

java.lang.Object
com.amazonaws.secretsmanager.caching.cache.LRUCache<K,V>

public class LRUCache<K,V> extends Object
An LRU cache based on the Java LinkedHashMap.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Construct a new cache with default settings.
    LRUCache(int maxSize)
    Construct a new cache based on the given max size.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clear the cache.
    boolean
    Determine if the cache contains the given key.
    get(K key)
    Return the value mapped to the given key.
    getAndPut(K key, V value)
    Return the previously mapped value and map a new value.
    Return the previously mapped value and remove the key.
    void
    put(K key, V value)
    Map a given key to the given value.
    void
    putAll(Map<? extends K,? extends V> map)
    Copies all of the mappings from the provided map to this cache.
    boolean
    putIfAbsent(K key, V value)
    Map a given key to the given value if not already mapped.
    boolean
    remove(K key)
    Remove a given key from the cache.
    boolean
    remove(K key, V oldValue)
    Remove a given key and value from the cache.
    void
    Remove all of the cached items.

    Methods inherited from class java.lang.Object

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

    • LRUCache

      public LRUCache()
      Construct a new cache with default settings.
    • LRUCache

      public LRUCache(int maxSize)
      Construct a new cache based on the given max size.
      Parameters:
      maxSize - The maximum number of items to store in the cache.
  • Method Details

    • get

      public V get(K key)
      Return the value mapped to the given key.
      Parameters:
      key - The key used to return the mapped value.
      Returns:
      The value mapped to the given key.
    • containsKey

      public boolean containsKey(K key)
      Determine if the cache contains the given key.
      Parameters:
      key - The key used to determine it there is a mapped value.
      Returns:
      True if a value is mapped to the given key.
    • put

      public void put(K key, V value)
      Map a given key to the given value.
      Parameters:
      key - The key to map to the given value.
      value - The value to map to the given key.
    • getAndPut

      public V getAndPut(K key, V value)
      Return the previously mapped value and map a new value.
      Parameters:
      key - The key to map to the given value.
      value - The value to map to the given key.
      Returns:
      The previously mapped value to the given key.
    • putAll

      public void putAll(Map<? extends K,? extends V> map)
      Copies all of the mappings from the provided map to this cache. These mappings will replace any keys currently in the cache.
      Parameters:
      map - The mappings to copy.
    • putIfAbsent

      public boolean putIfAbsent(K key, V value)
      Map a given key to the given value if not already mapped.
      Parameters:
      key - The key to map to the given value.
      value - The value to map to the given key.
      Returns:
      True if the mapping has been made.
    • remove

      public boolean remove(K key)
      Remove a given key from the cache.
      Parameters:
      key - The key to remove.
      Returns:
      True if the key has been removed.
    • remove

      public boolean remove(K key, V oldValue)
      Remove a given key and value from the cache.
      Parameters:
      key - The key to remove.
      oldValue - The value to remove.
      Returns:
      True if the key and oldValue has been removed.
    • getAndRemove

      public V getAndRemove(K key)
      Return the previously mapped value and remove the key.
      Parameters:
      key - The key to remove.
      Returns:
      The previously mapped value to the given key.
    • removeAll

      public void removeAll()
      Remove all of the cached items.
    • clear

      public void clear()
      Clear the cache.