Class Cache
- java.lang.Object
-
- edu.uiuc.ncsa.security.core.cache.Cache
-
- All Implemented Interfaces:
Map<Identifier,CachedObject>
public class Cache extends Object implements Map<Identifier,CachedObject>
This cache storesCachedObjects by a given key. The cached objects are always sorted by added date to the cache, which facilitates and optimizes aging retention policies. Each object to be cached should implement the interfaceCacheablewhich has a single method that gives back th associated key. This is used to retrieve objects from the cache (rather than cachedObjects which contain state about the entry and when it was made).Note that this is not tasked with saving cached objects or any other persistence activities. It is up to the application to set an manage its own policies.
Use
This containsCachedObjects but this does not mean you actually should ever make them. SinceCacheableobjects areIdentifiable, this means that simple invokingadd(Cacheable)will create a cached object internally. Invokingget(java.lang.Object)will return a cached object whose value (viaCachedObject.getValue()is the original cacheable object. Generally in OA4MP all useful objects (transactions, clients and pretty much anything with an identifier associated with it) are cacheable. If you need to cache something, use this, set your policies for aging and periodically callCleanup.Created by Jeff Gaynor
on Nov 11, 2010 at 1:02:04 PM
-
-
Constructor Summary
Constructors Constructor Description Cache()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CachedObjectadd(Cacheable cacheable)Convenience method to add an object with its key to the cache.voidclear()booleancontainsKey(Object key)booleancontainsObject(Cacheable cacheable)Checks if the cacheable object is in this cache.booleancontainsValue(Object value)Set<Map.Entry<Identifier,CachedObject>>entrySet()CachedObjectget(Object key)PriorityQueue<CachedObject>getSortedList()Sorted list of cached items, ordered by timestamp.TreeMap<Identifier,CachedObject>getTheRealCache()booleanisEmpty()Set<Identifier>keySet()Collection<? extends Cacheable>objectValues()Get the objects that have been cached.voidput(CachedObject co)CachedObjectput(Identifier key, CachedObject value)Using this rather thanadd(edu.uiuc.ncsa.security.core.cache.Cacheable)will let you cache anything you please, even objects (like connections to servers) that are not inherentlyIdentifiable.voidputAll(Map<? extends Identifier,? extends CachedObject> m)CachedObjectremove(Object key)intsize()StringtoString()Collection<CachedObject>values()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Method Detail
-
add
public CachedObject add(Cacheable cacheable)
Convenience method to add an object with its key to the cache. This creates the CachedObject wrapper to manage its state. If the object already exists in the cache, it updates its value.- Parameters:
cacheable-- Returns:
-
getSortedList
public PriorityQueue<CachedObject> getSortedList()
Sorted list of cached items, ordered by timestamp.- Returns:
-
getTheRealCache
public TreeMap<Identifier,CachedObject> getTheRealCache()
-
clear
public void clear()
- Specified by:
clearin interfaceMap<Identifier,CachedObject>
-
size
public int size()
- Specified by:
sizein interfaceMap<Identifier,CachedObject>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceMap<Identifier,CachedObject>
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKeyin interfaceMap<Identifier,CachedObject>
-
containsObject
public boolean containsObject(Cacheable cacheable)
Checks if the cacheable object is in this cache.- Parameters:
cacheable-- Returns:
-
objectValues
public Collection<? extends Cacheable> objectValues()
Get the objects that have been cached.- Returns:
-
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValuein interfaceMap<Identifier,CachedObject>
-
get
public CachedObject get(Object key)
- Specified by:
getin interfaceMap<Identifier,CachedObject>
-
put
public void put(CachedObject co)
-
put
public CachedObject put(Identifier key, CachedObject value)
Using this rather thanadd(edu.uiuc.ncsa.security.core.cache.Cacheable)will let you cache anything you please, even objects (like connections to servers) that are not inherentlyIdentifiable.- Specified by:
putin interfaceMap<Identifier,CachedObject>- Parameters:
key-value-- Returns:
-
remove
public CachedObject remove(Object key)
- Specified by:
removein interfaceMap<Identifier,CachedObject>
-
putAll
public void putAll(Map<? extends Identifier,? extends CachedObject> m)
- Specified by:
putAllin interfaceMap<Identifier,CachedObject>
-
keySet
public Set<Identifier> keySet()
- Specified by:
keySetin interfaceMap<Identifier,CachedObject>
-
values
public Collection<CachedObject> values()
- Specified by:
valuesin interfaceMap<Identifier,CachedObject>
-
entrySet
public Set<Map.Entry<Identifier,CachedObject>> entrySet()
- Specified by:
entrySetin interfaceMap<Identifier,CachedObject>
-
-