Package org.apache.shiro.cache
Interface Cache<K,V>
- Type Parameters:
K- KV- V
- All Known Implementing Classes:
MapCache
public interface Cache<K,V>
A Cache efficiently stores temporary objects primarily to improve an application's performance.
Shiro doesn't implement a full Cache mechanism itself, since that is outside the core competency of a Security framework. Instead, this interface provides an abstraction (wrapper) API on top of an underlying cache framework's cache instance (e.g. JCache, Ehcache, JCS, OSCache, JBossCache, TerraCotta, Coherence, GigaSpaces, etc., etc.), allowing a Shiro user to configure any cache mechanism they choose.
- Since:
- 0.2
-
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear all entries from the cache.Returns the Cached value stored under the specifiedkeyornullif there is no Cache entry for thatkey.keys()Returns a view of all the keys for entries contained in this cache.Adds a Cache entry.Remove the cache entry corresponding to the specified key.intsize()Returns the number of entries in the cache.values()Returns a view of all of the values contained in this cache.
-
Method Details
-
get
Returns the Cached value stored under the specifiedkeyornullif there is no Cache entry for thatkey.- Parameters:
key- the key that the value was previous added with- Returns:
- the cached object or
nullif there is no entry for the specifiedkey - Throws:
CacheException- if there is a problem accessing the underlying cache system
-
put
Adds a Cache entry.- 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
keyornullif there was previous value - Throws:
CacheException- if there is a problem accessing the underlying cache system
-
remove
Remove the cache entry corresponding to the specified key.- Parameters:
key- the key of the entry to be removed.- Returns:
- the previous value associated with the given
keyornullif there was previous value - Throws:
CacheException- if there is a problem accessing the underlying cache system
-
clear
Clear all entries from the cache.- Throws:
CacheException- if there is a problem accessing the underlying cache system
-
size
int size()Returns the number of entries in the cache.- Returns:
- the number of entries in the cache.
-
keys
Returns a view of all the keys for entries contained in this cache.- Returns:
- a view of all the keys for entries contained in this cache.
-
values
Collection<V> values()Returns a view of all of the values contained in this cache.- Returns:
- a view of all of the values contained in this cache.
-