Interface Cache<K,V>

Type Parameters:
K - type of the keys for the cache
V - type of cached elements
All Superinterfaces:
org.apache.shiro.cache.Cache<K,V>

public interface Cache<K,V> extends org.apache.shiro.cache.Cache<K,V>
The main interface for the cache. Provides methods to add, access, and remove entries from a cache.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Remove all elements from this cache.
    boolean
    contains(K key)
    Returns true if this cache contains an element with the specified key.
    get(K key)
    Returns the element with the specified key.
    Returns performance statistics of the cache or null if the cache does not support statistics.
    put(K key, V value)
    Put a new element to this cache.
    remove(K key)
    Remove the element with the specified key from this cache.
    removeAll(com.google.common.base.Predicate<K> predicate)
    Remove all elements with matching Predicate from this cache.
    int
    Returns the number of entries in the cache.

    Methods inherited from interface org.apache.shiro.cache.Cache

    keys, values
  • Method Details

    • clear

      void clear()
      Remove all elements from this cache.
      Specified by:
      clear in interface org.apache.shiro.cache.Cache<K,V>
    • contains

      boolean contains(K key)
      Returns true if this cache contains an element with the specified key.
      Parameters:
      key - key of the cached element
    • put

      V put(K key, V value)
      Put a new element to this cache.
      Specified by:
      put in interface org.apache.shiro.cache.Cache<K,V>
      Parameters:
      key - key of the element to cache
      value - element that should be cached
      Returns:
      previous cached value or null
    • remove

      V remove(K key)
      Remove the element with the specified key from this cache. Return previous cached value.
      Specified by:
      remove in interface org.apache.shiro.cache.Cache<K,V>
      Parameters:
      key - key of the cached element
      Returns:
      previous cached value or null
    • removeAll

      Iterable<V> removeAll(com.google.common.base.Predicate<K> predicate)
      Remove all elements with matching Predicate from this cache. The method returns all previous cached values.
      Parameters:
      predicate - predicate to match cache keys
      Since:
      1.9
    • size

      int size()
      Returns the number of entries in the cache.
      Specified by:
      size in interface org.apache.shiro.cache.Cache<K,V>
      Since:
      2.0.0
    • get

      V get(K key)
      Returns the element with the specified key. Returns null if the cache contains no element with the specified key.
      Specified by:
      get in interface org.apache.shiro.cache.Cache<K,V>
      Parameters:
      key - key of the cached element
      Returns:
      The cached element with the specified key or null
    • getStatistics

      CacheStatistics getStatistics()
      Returns performance statistics of the cache or null if the cache does not support statistics. The returned statistic is a snapshot of the current performance.
      Since:
      2.0.0