public class Cache extends Object implements Map<Identifier,CachedObject>
CachedObject
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 interface
Cacheable
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.
CachedObject
s but this does not mean you actually should ever make them.
Since Cacheable
objects are Identifiable
,
this means that simple invoking add(Cacheable)
will create a cached object internally.
Invoking get(java.lang.Object)
will return a cached object whose value (via CachedObject.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 call Cleanup
.
Created by Jeff Gaynor
on Nov 11, 2010 at 1:02:04 PM
Constructor and Description |
---|
Cache() |
Modifier and Type | Method and 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 than
add(edu.uiuc.ncsa.security.core.cache.Cacheable) will let you cache anything you please, even objects
(like connections to servers) that are not inherently Identifiable . |
void |
putAll(Map<? extends Identifier,? extends CachedObject> m) |
CachedObject |
remove(Object key) |
int |
size() |
String |
toString() |
Collection<CachedObject> |
values() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
public CachedObject add(Cacheable cacheable)
cacheable
- public PriorityQueue<CachedObject> getSortedList()
public TreeMap<Identifier,CachedObject> getTheRealCache()
public void clear()
clear
in interface Map<Identifier,CachedObject>
public int size()
size
in interface Map<Identifier,CachedObject>
public boolean isEmpty()
isEmpty
in interface Map<Identifier,CachedObject>
public boolean containsKey(Object key)
containsKey
in interface Map<Identifier,CachedObject>
public boolean containsObject(Cacheable cacheable)
cacheable
- public Collection<? extends Cacheable> objectValues()
public boolean containsValue(Object value)
containsValue
in interface Map<Identifier,CachedObject>
public CachedObject get(Object key)
get
in interface Map<Identifier,CachedObject>
public void put(CachedObject co)
public CachedObject put(Identifier key, CachedObject value)
add(edu.uiuc.ncsa.security.core.cache.Cacheable)
will let you cache anything you please, even objects
(like connections to servers) that are not inherently Identifiable
.put
in interface Map<Identifier,CachedObject>
key
- value
- public CachedObject remove(Object key)
remove
in interface Map<Identifier,CachedObject>
public void putAll(Map<? extends Identifier,? extends CachedObject> m)
putAll
in interface Map<Identifier,CachedObject>
public Set<Identifier> keySet()
keySet
in interface Map<Identifier,CachedObject>
public Collection<CachedObject> values()
values
in interface Map<Identifier,CachedObject>
public Set<Map.Entry<Identifier,CachedObject>> entrySet()
entrySet
in interface Map<Identifier,CachedObject>
Copyright © 2019. All Rights Reserved.