org.softamis.net.cache.impl
Class MapBasedCache<K extends java.io.Serializable,V extends java.io.Serializable>

java.lang.Object
  extended by org.softamis.net.cache.impl.MapBasedCache<K,V>
Type Parameters:
K - type of keys used to identify cache items
V - type of values stored in the cache
All Implemented Interfaces:
SimpleCache<K,V>
Direct Known Subclasses:
DefaultDistributedCache

public class MapBasedCache<K extends java.io.Serializable,V extends java.io.Serializable>
extends java.lang.Object
implements SimpleCache<K,V>

Generic implementation of simple cache. It uses java.util.Map as underlying storage for items stored in the cache.

Author:
Andrew Sazonov

Field Summary
protected  java.lang.Object fCacheLock
          Object used as lock to control access to cache' data
protected  java.util.Map<K,V> fData
          Map that contains item stored in the cache
protected static org.apache.commons.logging.Log fLog
           
 
Constructor Summary
MapBasedCache()
           
 
Method Summary
 void clear()
          Clears cache content
protected  void doAfterObjectAdded(K aKey, V aValue)
          Method called after adding object to the cache.
protected  void doAfterUpdate()
          Method called after cache updates.
 java.util.Set<K> getKeys()
          Returns set of keys for items stored in cache
 V getObject(K aKey)
          Returns object from cache for given key
 java.util.Set<V> getValues()
          Returns items stored in the cache
 void saveObject(K aKey, V aValue)
          Stores object in cache
 int size()
          Returns amount of items stored in cache
 void update(java.util.Map<K,V> aData)
          Updates content of cache by given values (old values will be removed)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fLog

protected static final org.apache.commons.logging.Log fLog

fCacheLock

protected final java.lang.Object fCacheLock
Object used as lock to control access to cache' data


fData

protected java.util.Map<K extends java.io.Serializable,V extends java.io.Serializable> fData
Map that contains item stored in the cache

Constructor Detail

MapBasedCache

public MapBasedCache()
Method Detail

saveObject

public void saveObject(K aKey,
                       V aValue)
Description copied from interface: SimpleCache
Stores object in cache

Specified by:
saveObject in interface SimpleCache<K extends java.io.Serializable,V extends java.io.Serializable>
Parameters:
aKey - key of object
aValue - item value

doAfterObjectAdded

protected void doAfterObjectAdded(K aKey,
                                  V aValue)
Method called after adding object to the cache. Inherited classes may override it to add futher processing of insertion of items to cache (for example, by issuing necessary network notifications)

Parameters:
aKey - key of item
aValue - item added

doAfterUpdate

protected void doAfterUpdate()
Method called after cache updates. Inherited classes may override it to implement additional processing such as issuing networking notification for synchronization.


getObject

public V getObject(K aKey)
Description copied from interface: SimpleCache
Returns object from cache for given key

Specified by:
getObject in interface SimpleCache<K extends java.io.Serializable,V extends java.io.Serializable>
Parameters:
aKey - key of the object
Returns:
object stored in cache under given key, null if there is no item in the cache for given key

clear

public void clear()
Description copied from interface: SimpleCache
Clears cache content

Specified by:
clear in interface SimpleCache<K extends java.io.Serializable,V extends java.io.Serializable>

update

public void update(java.util.Map<K,V> aData)
Description copied from interface: SimpleCache
Updates content of cache by given values (old values will be removed)

Specified by:
update in interface SimpleCache<K extends java.io.Serializable,V extends java.io.Serializable>
Parameters:
aData - new content of the cache

size

public int size()
Description copied from interface: SimpleCache
Returns amount of items stored in cache

Specified by:
size in interface SimpleCache<K extends java.io.Serializable,V extends java.io.Serializable>
Returns:
items count

getValues

public java.util.Set<V> getValues()
Description copied from interface: SimpleCache
Returns items stored in the cache

Specified by:
getValues in interface SimpleCache<K extends java.io.Serializable,V extends java.io.Serializable>
Returns:
items stored int the cache

getKeys

public java.util.Set<K> getKeys()
Description copied from interface: SimpleCache
Returns set of keys for items stored in cache

Specified by:
getKeys in interface SimpleCache<K extends java.io.Serializable,V extends java.io.Serializable>
Returns:
set of keys