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 storesCachedObject
s 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 interfaceCacheable
which 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 containsCachedObject
s but this does not mean you actually should ever make them. SinceCacheable
objects 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 CachedObject
add(Cacheable cacheable)
Convenience method to add an object with its key to the cache.void
clear()
boolean
containsKey(Object key)
boolean
containsObject(Cacheable cacheable)
Checks if the cacheable object is in this cache.boolean
containsValue(Object value)
Set<Map.Entry<Identifier,CachedObject>>
entrySet()
CachedObject
get(Object key)
PriorityQueue<CachedObject>
getSortedList()
Sorted list of cached items, ordered by timestamp.TreeMap<Identifier,CachedObject>
getTheRealCache()
boolean
isEmpty()
Set<Identifier>
keySet()
Collection<? extends Cacheable>
objectValues()
Get the objects that have been cached.void
put(CachedObject co)
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
.void
putAll(Map<? extends Identifier,? extends CachedObject> m)
CachedObject
remove(Object key)
int
size()
String
toString()
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:
clear
in interfaceMap<Identifier,CachedObject>
-
size
public int size()
- Specified by:
size
in interfaceMap<Identifier,CachedObject>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfaceMap<Identifier,CachedObject>
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKey
in 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:
containsValue
in interfaceMap<Identifier,CachedObject>
-
get
public CachedObject get(Object key)
- Specified by:
get
in 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:
put
in interfaceMap<Identifier,CachedObject>
- Parameters:
key
-value
-- Returns:
-
remove
public CachedObject remove(Object key)
- Specified by:
remove
in interfaceMap<Identifier,CachedObject>
-
putAll
public void putAll(Map<? extends Identifier,? extends CachedObject> m)
- Specified by:
putAll
in interfaceMap<Identifier,CachedObject>
-
keySet
public Set<Identifier> keySet()
- Specified by:
keySet
in interfaceMap<Identifier,CachedObject>
-
values
public Collection<CachedObject> values()
- Specified by:
values
in interfaceMap<Identifier,CachedObject>
-
entrySet
public Set<Map.Entry<Identifier,CachedObject>> entrySet()
- Specified by:
entrySet
in interfaceMap<Identifier,CachedObject>
-
-