Class EhCache<K,V>

java.lang.Object
org.apache.shiro.cache.ehcache.EhCache<K,V>
All Implemented Interfaces:
org.apache.shiro.cache.Cache<K,V>

public class EhCache<K,V> extends Object implements org.apache.shiro.cache.Cache<K,V>
Shiro Cache implementation that wraps an Ehcache instance.
Since:
0.2
  • Constructor Summary

    Constructors
    Constructor
    Description
    EhCache(net.sf.ehcache.Ehcache cache)
    Constructs a new EhCache instance with the given cache.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Removes all elements in the cache, but leaves the cache in a useable state.
    get(K key)
    Gets a value of an element which matches the given key.
    long
    Returns the size (in bytes) that this EhCache's disk store is consuming or -1 if that number is unknown or cannot be calculated.
    long
    Returns the size (in bytes) that this EhCache's memory store is using (RAM), or -1 if that number is unknown or cannot be calculated.
    long
    Returns the size (in bytes) that this EhCache is using in memory (RAM), or -1 if that number is unknown or cannot be calculated.
     
    put(K key, V value)
    Puts an object into the cache.
    remove(K key)
    Removes the element which matches the key.
    int
     
    Returns "EhCache [" + cache.getName() + "]"
     

    Methods inherited from class java.lang.Object

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

    • EhCache

      public EhCache(net.sf.ehcache.Ehcache cache)
      Constructs a new EhCache instance with the given cache.
      Parameters:
      cache - - delegate EhCache instance this Shiro cache instance will wrap.
  • Method Details

    • get

      public V get(K key) throws org.apache.shiro.cache.CacheException
      Gets a value of an element which matches the given key.
      Specified by:
      get in interface org.apache.shiro.cache.Cache<K,V>
      Parameters:
      key - the key of the element to return.
      Returns:
      The value placed into the cache with an earlier put, or null if not found or expired
      Throws:
      org.apache.shiro.cache.CacheException
    • put

      public V put(K key, V value) throws org.apache.shiro.cache.CacheException
      Puts an object into the cache.
      Specified by:
      put in interface org.apache.shiro.cache.Cache<K,V>
      Parameters:
      key - the key.
      value - the value.
      Throws:
      org.apache.shiro.cache.CacheException
    • remove

      public V remove(K key) throws org.apache.shiro.cache.CacheException
      Removes the element which matches the key.

      If no element matches, nothing is removed and no Exception is thrown.

      Specified by:
      remove in interface org.apache.shiro.cache.Cache<K,V>
      Parameters:
      key - the key of the element to remove
      Throws:
      org.apache.shiro.cache.CacheException
    • clear

      public void clear() throws org.apache.shiro.cache.CacheException
      Removes all elements in the cache, but leaves the cache in a useable state.
      Specified by:
      clear in interface org.apache.shiro.cache.Cache<K,V>
      Throws:
      org.apache.shiro.cache.CacheException
    • size

      public int size()
      Specified by:
      size in interface org.apache.shiro.cache.Cache<K,V>
    • keys

      public Set<K> keys()
      Specified by:
      keys in interface org.apache.shiro.cache.Cache<K,V>
    • values

      public Collection<V> values()
      Specified by:
      values in interface org.apache.shiro.cache.Cache<K,V>
    • getMemoryUsage

      public long getMemoryUsage()
      Returns the size (in bytes) that this EhCache is using in memory (RAM), or -1 if that number is unknown or cannot be calculated.
      Returns:
      the size (in bytes) that this EhCache is using in memory (RAM), or -1 if that number is unknown or cannot be calculated.
    • getMemoryStoreSize

      public long getMemoryStoreSize()
      Returns the size (in bytes) that this EhCache's memory store is using (RAM), or -1 if that number is unknown or cannot be calculated.
      Returns:
      the size (in bytes) that this EhCache's memory store is using (RAM), or -1 if that number is unknown or cannot be calculated.
    • getDiskStoreSize

      public long getDiskStoreSize()
      Returns the size (in bytes) that this EhCache's disk store is consuming or -1 if that number is unknown or cannot be calculated.
      Returns:
      the size (in bytes) that this EhCache's disk store is consuming or -1 if that number is unknown or cannot be calculated.
    • toString

      public String toString()
      Returns "EhCache [" + cache.getName() + "]"
      Overrides:
      toString in class Object
      Returns:
      "EhCache [" + cache.getName() + "]"