|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.bankframe.services.cache.GenericCache
This class provides generic caching functionality using a local cache. It implements
the java.util.Map
interface. This class uses the supplied Map
implementation to maintain consistency between the cache and the data store. The
supplied Map implementation must store and read its contents from some permanent
data store. An object will remain in the cache until it expires. When the object
expires is determined by the CachePolicy object. The Cache policy's cleanup() method
will be called at the end of the following methods:
NullPolicy
.
Nested Class Summary |
Nested classes inherited from class java.util.Map |
java.util.Map.Entry |
Constructor Summary | |
GenericCache()
Default Constructor |
|
GenericCache(CachePolicy policy)
Constructor |
|
GenericCache(java.util.Map persistentMap)
Constructor |
|
GenericCache(java.util.Map persistentMap,
CachePolicy policy)
Constructor |
Method Summary | |
void |
cleanup()
This method cleans up the cache by removing un-needed entries |
void |
clear()
This method clears the cache. |
boolean |
containsKey(java.lang.Object key)
|
boolean |
containsValue(java.lang.Object value)
|
void |
enableCaching(boolean enableCache)
This method enables or disables caching. |
java.util.Set |
entrySet()
|
boolean |
equals(java.lang.Object o)
|
java.lang.Object |
get(java.lang.Object key)
This method retrieves the specified object, if it is not in the cacheit will be fetched from the data store. |
CachePolicy |
getCachePolicy()
This method gets the CachePolicy object for this Cache |
java.lang.Object |
getFromPersistentMap(java.lang.Object key)
This method bypasses the memory cache and will get the object from the underlying data store |
java.lang.String |
getName()
Returns the name. |
java.util.Map |
getPersistentMap()
|
int |
hashCode()
|
boolean |
isEmpty()
|
java.util.Set |
keySet()
This method gets all the keys in the cache |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
This method updates the specified object to the data-store. |
void |
putAll(java.util.Map values)
This method places the specified values in the cache and the data-store. |
java.lang.Object |
remove(java.lang.Object key)
This method removes the specified object from the cache and the data store. |
void |
remove(java.util.Set keySet)
This method removes the specified keys from the cache and the data store. |
void |
removeAll()
Removes all objects from the cache and from the data store. |
void |
setCachePolicy(CachePolicy policy)
This method sets the CachePolicy object for this Cache |
void |
setName(java.lang.String name)
Returns the value. |
void |
setPersistentMap(java.util.Map map)
|
int |
size()
|
java.lang.String |
toString()
This method converts the cache to a String representation |
java.util.Collection |
values()
|
Methods inherited from class java.lang.Object |
getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public GenericCache()
public GenericCache(CachePolicy policy)
public GenericCache(java.util.Map persistentMap)
persistentMap
- Map instance that persists data in the cache
to the data storepublic GenericCache(java.util.Map persistentMap, CachePolicy policy)
persistentMap
- Map instance that persists data in the cache
to the data storepolicy
- Policy object defining behaviour for removing objects from cacheMethod Detail |
public void cleanup()
cleanup
in interface Cache
public void clear()
clear
in interface java.util.Map
public boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map
Invokes this.get(Object key) and checks if value returned is null. This will ensure that if an entry exists
and a cache policy is used, the entry timeout will be updated so it is available for use again.
public boolean containsValue(java.lang.Object value)
containsValue
in interface java.util.Map
Note that the cache may contain the value, but the key may have expired and is due to be removed.
This means that the cache may not have the value the next time this method is called.
public void enableCaching(boolean enableCache)
enableCaching
in interface Cache
enableCache
- true to enable, false to disablepublic java.util.Set entrySet()
entrySet
in interface java.util.Map
Map
public boolean equals(java.lang.Object o)
equals
in interface java.util.Map
Map
public java.lang.Object get(java.lang.Object key)
get
in interface java.util.Map
key
- Unique key identifying the object
public CachePolicy getCachePolicy()
getCachePolicy
in interface Cache
public java.lang.Object getFromPersistentMap(java.lang.Object key)
key
- Unique key identifying the object
public int hashCode()
hashCode
in interface java.util.Map
Map
public boolean isEmpty()
isEmpty
in interface java.util.Map
Map
public java.util.Set keySet()
keySet
in interface java.util.Map
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
put
in interface java.util.Map
key
- Unique key identifying the objectvalue
- The objectpublic void putAll(java.util.Map values)
putAll
in interface java.util.Map
public java.lang.Object remove(java.lang.Object key)
remove
in interface java.util.Map
key
- Unique key identifying the object to removepublic void remove(java.util.Set keySet)
remove
in interface Cache
keySet
- the set of keys to removepublic void removeAll()
removeAll
in interface Cache
public void setCachePolicy(CachePolicy policy)
setCachePolicy
in interface Cache
policy
- The new cache policypublic int size()
size
in interface java.util.Map
Map
public java.lang.String toString()
public java.util.Collection values()
values
in interface java.util.Map
Map
public java.util.Map getPersistentMap()
public void setPersistentMap(java.util.Map map)
setPersistentMap
in interface PersistentCache
map
- public java.lang.String getName()
NamedCache
getName
in interface NamedCache
NamedCache.getName()
public void setName(java.lang.String name)
NamedCache
setName
in interface NamedCache
name
- StringNamedCache.setName(String)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |