com.bankframe.services.cache
Class GenericCache

java.lang.Object
  extended bycom.bankframe.services.cache.GenericCache
All Implemented Interfaces:
Cache, java.util.Map, NamedCache, PersistentCache
Direct Known Subclasses:
JMSCache, MergedDataPacketsCache

public class GenericCache
extends java.lang.Object
implements PersistentCache, NamedCache

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:

Note: The default policy used if one is not specified is the NullPolicy.

Author:
Engineering

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

GenericCache

public GenericCache()
Default Constructor


GenericCache

public GenericCache(CachePolicy policy)
Constructor


GenericCache

public GenericCache(java.util.Map persistentMap)
Constructor

Parameters:
persistentMap - Map instance that persists data in the cache to the data store

GenericCache

public GenericCache(java.util.Map persistentMap,
                    CachePolicy policy)
Constructor

Parameters:
persistentMap - Map instance that persists data in the cache to the data store
policy - Policy object defining behaviour for removing objects from cache
Method Detail

cleanup

public void cleanup()
This method cleans up the cache by removing un-needed entries

Specified by:
cleanup in interface Cache

clear

public void clear()
This method clears the cache. Does not remove entries from the persistent map

Specified by:
clear in interface java.util.Map

containsKey

public boolean containsKey(java.lang.Object key)
Specified by:
containsKey in interface java.util.Map
See Also:
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.

containsValue

public boolean containsValue(java.lang.Object value)
Specified by:
containsValue in interface java.util.Map
See Also:
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.

enableCaching

public void enableCaching(boolean enableCache)
This method enables or disables caching. When caching is disabled the cache passes all operations on to the persistent map instance.

Specified by:
enableCaching in interface Cache
Parameters:
enableCache - true to enable, false to disable

entrySet

public java.util.Set entrySet()
Specified by:
entrySet in interface java.util.Map
See Also:
Map

equals

public boolean equals(java.lang.Object o)
Specified by:
equals in interface java.util.Map
See Also:
Map

get

public 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.

Specified by:
get in interface java.util.Map
Parameters:
key - Unique key identifying the object
Returns:
Instance of the object

getCachePolicy

public CachePolicy getCachePolicy()
This method gets the CachePolicy object for this Cache

Specified by:
getCachePolicy in interface Cache
Returns:
CachePolicy instance or null if there is no CachePolicy

getFromPersistentMap

public java.lang.Object getFromPersistentMap(java.lang.Object key)
This method bypasses the memory cache and will get the object from the underlying data store

Parameters:
key - Unique key identifying the object
Returns:
Instance of the object

hashCode

public int hashCode()
Specified by:
hashCode in interface java.util.Map
See Also:
Map

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map
See Also:
Map

keySet

public java.util.Set keySet()
This method gets all the keys in the cache

Specified by:
keySet in interface java.util.Map

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
This method updates the specified object to the data-store. It also updates the reference stored in the cache. If the object does not exist in the data-store it will be created.

Specified by:
put in interface java.util.Map
Parameters:
key - Unique key identifying the object
value - The object

putAll

public void putAll(java.util.Map values)
This method places the specified values in the cache and the data-store. :param values a map of values to add to the cache.

Specified by:
putAll in interface java.util.Map

remove

public java.lang.Object remove(java.lang.Object key)
This method removes the specified object from the cache and the data store.

Specified by:
remove in interface java.util.Map
Parameters:
key - Unique key identifying the object to remove

remove

public void remove(java.util.Set keySet)
This method removes the specified keys from the cache and the data store.

Specified by:
remove in interface Cache
Parameters:
keySet - the set of keys to remove

removeAll

public void removeAll()
Removes all objects from the cache and from the data store. Use this method with caution!

Specified by:
removeAll in interface Cache

setCachePolicy

public void setCachePolicy(CachePolicy policy)
This method sets the CachePolicy object for this Cache

Specified by:
setCachePolicy in interface Cache
Parameters:
policy - The new cache policy

size

public int size()
Specified by:
size in interface java.util.Map
See Also:
Map

toString

public java.lang.String toString()
This method converts the cache to a String representation

Returns:
a string representation

values

public java.util.Collection values()
Specified by:
values in interface java.util.Map
See Also:
Map

getPersistentMap

public java.util.Map getPersistentMap()
Returns:

setPersistentMap

public void setPersistentMap(java.util.Map map)
Specified by:
setPersistentMap in interface PersistentCache
Parameters:
map -

getName

public java.lang.String getName()
Description copied from interface: NamedCache
Returns the name.

Specified by:
getName in interface NamedCache
Returns:
String
See Also:
NamedCache.getName()

setName

public void setName(java.lang.String name)
Description copied from interface: NamedCache
Returns the value.

Specified by:
setName in interface NamedCache
Parameters:
name - String
See Also:
NamedCache.setName(String)


Copyright © 2004 Siebel Systems, Inc. All rights reserved.