edu.northwestern.at.utils.cache

## Class SoftReferenceCache<K,V>

- java.lang.Object
- - edu.northwestern.at.utils.cache.SoftReferenceCache<K,V>

- All Implemented Interfaces:
    Cache<K,V>

      public class SoftReferenceCache<K,V>
      extends java.lang.Object
      implements Cache<K,V>

  A cache that uses soft references. Values in this cache are expired by the VM in response to memory needs. For more information on how this works, see the JavaDoc for the `java.lang.ref` package.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected java.util.Map<K,java.lang.ref.SoftReference<V>>` | `cacheMap` Map holding cached values.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SoftReferenceCache()` Create cache.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clear()` Clear all entries in the cache.
    `boolean` | `containsKey(K key)` True if cache contains a specified key.
    `V` | `get(K key)` Retrieve a cached value.
    `V` | `put(K key, V value)` Add or replace a cached value.
    `V` | `remove(K key)` Remove a specific entry from the cache.
    `int` | `size()` Return current size of cache.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### cacheMap

          protected java.util.Map<K,java.lang.ref.SoftReference<V>> cacheMap

      Map holding cached values.

  - ### Constructor Detail

    - #### SoftReferenceCache

          public SoftReferenceCache()

      Create cache.

  - ### Method Detail

    - #### clear

          public void clear()

      Clear all entries in the cache.
      Specified by:
        `clear` in interface `Cache<K,V>`

    - #### containsKey

          public boolean containsKey(K key)

      True if cache contains a specified key.
      Specified by:
        `containsKey` in interface `Cache<K,V>`
      Parameters:
        `key` - The key to look up.
      Returns:
        true if the cache contains the key.

    - #### get

          public V get(K key)

      Retrieve a cached value.
      Specified by:
        `get` in interface `Cache<K,V>`
      Parameters:
        `key` - The key of the entry to retrieve.
      Returns:
        The value of the cached entry specified by key; null if the cache does not contain the key.

    - #### put

          public V put(K key,
              V value)

      Add or replace a cached value.
      Specified by:
        `put` in interface `Cache<K,V>`
      Parameters:
        `key` - The key of the entry to add.
        `value` - The value of the entry to add.
      Returns:
        The value of any existing cached entry specified by the key; null if the cache does not contain the key.

    - #### remove

          public V remove(K key)

      Remove a specific entry from the cache.
      Specified by:
        `remove` in interface `Cache<K,V>`
      Parameters:
        `key` - The key of the entry to remove.
      Returns:
        The entry removed, or null if none.

    - #### size

          public int size()

      Return current size of cache.
      Specified by:
        `size` in interface `Cache<K,V>`
      Returns:
        Number of entries (keys) currently stored in cache.