org.apache.shiro.cache
Class MapCache<K,V>

java.lang.Object
  extended by org.apache.shiro.cache.MapCache<K,V>
All Implemented Interfaces:
Cache<K,V>

public class MapCache<K,V>
extends Object
implements Cache<K,V>

A MapCache is a Cache implementation that uses a backing Map instance to store and retrieve cached data.

Since:
1.0

Constructor Summary
MapCache(String name, Map<K,V> backingMap)
           
 
Method Summary
 void clear()
          Clear all entries from the cache.
 V get(K key)
          Returns the Cached value stored under the specified key or null if there is no Cache entry for that key.
 Set<K> keys()
          Returns a view of all the keys for entries contained in this cache.
 V put(K key, V value)
          Adds a Cache entry.
 V remove(K key)
          Remove the cache entry corresponding to the specified key.
 int size()
          Returns the number of entries in the cache.
 String toString()
           
 Collection<V> values()
          Returns a view of all of the values contained in this cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MapCache

public MapCache(String name,
                Map<K,V> backingMap)
Method Detail

get

public V get(K key)
      throws CacheException
Description copied from interface: Cache
Returns the Cached value stored under the specified key or null if there is no Cache entry for that key.

Specified by:
get in interface Cache<K,V>
Parameters:
key - the key that the value was previous added with
Returns:
the cached object or null if there is no entry for the specified key
Throws:
CacheException - if there is a problem accessing the underlying cache system

put

public V put(K key,
             V value)
      throws CacheException
Description copied from interface: Cache
Adds a Cache entry.

Specified by:
put in interface Cache<K,V>
Parameters:
key - the key used to identify the object being stored.
value - the value to be stored in the cache.
Returns:
the previous value associated with the given key or null if there was previous value
Throws:
CacheException - if there is a problem accessing the underlying cache system

remove

public V remove(K key)
         throws CacheException
Description copied from interface: Cache
Remove the cache entry corresponding to the specified key.

Specified by:
remove in interface Cache<K,V>
Parameters:
key - the key of the entry to be removed.
Returns:
the previous value associated with the given key or null if there was previous value
Throws:
CacheException - if there is a problem accessing the underlying cache system

clear

public void clear()
           throws CacheException
Description copied from interface: Cache
Clear all entries from the cache.

Specified by:
clear in interface Cache<K,V>
Throws:
CacheException - if there is a problem accessing the underlying cache system

size

public int size()
Description copied from interface: Cache
Returns the number of entries in the cache.

Specified by:
size in interface Cache<K,V>
Returns:
the number of entries in the cache.

keys

public Set<K> keys()
Description copied from interface: Cache
Returns a view of all the keys for entries contained in this cache.

Specified by:
keys in interface Cache<K,V>
Returns:
a view of all the keys for entries contained in this cache.

values

public Collection<V> values()
Description copied from interface: Cache
Returns a view of all of the values contained in this cache.

Specified by:
values in interface Cache<K,V>
Returns:
a view of all of the values contained in this cache.

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2004-2012 The Apache Software Foundation. All Rights Reserved.