|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.bankframe.services.cache.GenericCache
public class 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/interfaces inherited from interface java.util.Map |
|---|
Map.Entry<K,V> |
| Constructor Summary | |
|---|---|
GenericCache()
Default Constructor |
|
GenericCache(CachePolicy policy)
Constructor |
|
GenericCache(Map persistentMap)
Constructor |
|
GenericCache(Map persistentMap,
CachePolicy policy)
Constructor |
|
| Method Summary | |
|---|---|
void |
addCacheListener(Object key,
CacheListener listener)
Adds a CacheListener for a specified key. |
void |
cleanup()
This method cleans up the cache by removing un-needed entries |
void |
clear()
This method clears the cache. |
boolean |
containsKey(Object key)
|
boolean |
containsValue(Object value)
|
void |
enableCaching(boolean enableCache)
This method enables or disables caching. |
Set |
entrySet()
|
boolean |
equals(Object o)
|
Object |
get(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 |
Object |
getFromPersistentMap(Object key)
This method bypasses the memory cache and will get the object from the underlying data store |
String |
getName()
Returns the name. |
Map |
getPersistentMap()
|
int |
hashCode()
|
boolean |
isEmpty()
|
Set |
keySet()
This method gets all the keys in the cache |
Object |
put(Object key,
Object value)
This method updates the specified object to the data-store. |
void |
putAll(Map values)
This method places the specified values in the cache and the data-store. |
Object |
remove(Object key)
This method removes the specified object from the cache and the data store. |
void |
remove(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 |
removeCacheListener(Object key,
CacheListener listener)
Removes a CacheListener for a specified key. |
void |
setCachePolicy(CachePolicy policy)
This method sets the CachePolicy object for this Cache |
void |
setName(String name)
Returns the value. |
void |
setPersistentMap(Map map)
|
int |
size()
|
String |
toString()
This method converts the cache to a String representation |
Collection |
values()
see java.util.Map |
| Methods inherited from class java.lang.Object |
|---|
getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public GenericCache()
public GenericCache(CachePolicy policy)
policy - The caching policy to use for this cachepublic GenericCache(Map persistentMap)
persistentMap - Map instance that persists data in the cache
to the data store
public GenericCache(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 cache| Method Detail |
|---|
public void cleanup()
cleanup in interface Cachepublic void clear()
clear in interface Mappublic boolean containsKey(Object key)
containsKey in interface MapInvokes 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(Object value)
containsValue in interface MapNote 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 CacheenableCache - true to enable, false to disablepublic Set entrySet()
entrySet in interface MapMappublic boolean equals(Object o)
equals in interface Mapequals in class ObjectMappublic Object get(Object key)
get in interface Mapkey - Unique key identifying the object
public CachePolicy getCachePolicy()
getCachePolicy in interface Cachepublic Object getFromPersistentMap(Object key)
key - Unique key identifying the object
public int hashCode()
hashCode in interface MaphashCode in class ObjectMappublic boolean isEmpty()
isEmpty in interface MapMappublic Set keySet()
keySet in interface Map
public Object put(Object key,
Object value)
put in interface Mapkey - Unique key identifying the objectvalue - The objectpublic void putAll(Map values)
putAll in interface Mappublic Object remove(Object key)
remove in interface Mapkey - Unique key identifying the object to removepublic void remove(Set keySet)
remove in interface CachekeySet - the set of keys to removepublic void removeAll()
removeAll in interface Cachepublic void setCachePolicy(CachePolicy policy)
setCachePolicy in interface Cachepolicy - The new cache policypublic int size()
size in interface MapMappublic String toString()
toString in class Objectpublic Collection values()
values in interface Mappublic Map getPersistentMap()
public void setPersistentMap(Map map)
setPersistentMap in interface PersistentCachemap - public String getName()
NamedCache
getName in interface NamedCacheNamedCache.getName()public void setName(String name)
NamedCache
setName in interface NamedCachename - StringNamedCache.setName(String)
public void addCacheListener(Object key,
CacheListener listener)
addCacheListener in interface Cache
public void removeCacheListener(Object key,
CacheListener listener)
removeCacheListener in interface Cache
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||