Package org.apache.groovy.json.internal

# Class SimpleCache<K,V>

java.lang.Object
org.apache.groovy.json.internal.SimpleCache<K,V>

Type Parameters:
  `K` - the key type
  `V` - the value type

All Implemented Interfaces:
  `Cache<K,V>`

public class SimpleCache<K,V> extends Object implements Cache<K,V>
Thin adapter that exposes `CommonCache` through the internal `Cache` API.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SimpleCache(int limit)`
  Creates an LRU cache with the supplied size limit.
  `SimpleCache(int limit, CacheType type)`
  Creates a cache with the supplied size limit and eviction policy.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `V`
  `get(K key)`
  Retrieves a value and updates cache state as needed.
  `V`
  `getSilent(K key)`
  Retrieves a value using implementation-specific silent access semantics.
  `void`
  `put(K key, V value)`
  Stores a value under the supplied key.
  `void`
  `remove(K key)`
  Removes the value stored for the supplied key.
  `int`
  `size()`
  Returns the current number of cached entries.
  `String`
  `toString()`
  Returns the underlying cache state as a string.

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

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

- ## Constructor Details

  - ### SimpleCache

    public SimpleCache(int limit, CacheType type)
    Creates a cache with the supplied size limit and eviction policy.
    Parameters:
      `limit` - the maximum number of entries
      `type` - the eviction strategy

  - ### SimpleCache

    public SimpleCache(int limit)
    Creates an LRU cache with the supplied size limit.
    Parameters:
      `limit` - the maximum number of entries

- ## Method Details

  - ### put

    public void put(K key, V value)
    Stores a value under the supplied key.
    Specified by:
      `put` in interface `Cache<K,V>`
    Parameters:
      `key` - the cache key
      `value` - the cached value

  - ### get

    public V get(K key)
    Retrieves a value and updates cache state as needed.
    Specified by:
      `get` in interface `Cache<K,V>`
    Parameters:
      `key` - the cache key
    Returns:
      the cached value, or `null` if absent

  - ### getSilent

    public V getSilent(K key)
    Retrieves a value using implementation-specific silent access semantics.
    Specified by:
      `getSilent` in interface `Cache<K,V>`
    Parameters:
      `key` - the cache key
    Returns:
      the cached value, or `null` if absent

  - ### remove

    public void remove(K key)
    Removes the value stored for the supplied key.
    Specified by:
      `remove` in interface `Cache<K,V>`
    Parameters:
      `key` - the cache key

  - ### size

    public int size()
    Returns the current number of cached entries.
    Specified by:
      `size` in interface `Cache<K,V>`
    Returns:
      the cache size

  - ### toString

    public String toString()
    Returns the underlying cache state as a string.
    Overrides:
      `toString` in class `Object`
    Returns:
      the cache state string