org.activemath.presentation
Class FragmentCache

java.lang.Object
  extended by org.activemath.presentation.FragmentCache
All Implemented Interfaces:
Serializable, CacheControl, StorageListener

public class FragmentCache
extends Object
implements CacheControl, StorageListener

Store the translation to the various assembly formats of the fetched fragments. Fragments of the same Item are stored in the same cache group so they can be removed together. This cache also listens for removals from the Item cache, so that corresponding fragments are removed as well.

Version:
$Revision: 1.11 $ $Date: 2005/02/22 09:57:21 $
See Also:
Serialized Form

Field Summary
static String CACHE_ID
           
protected static Category log
           
 
Constructor Summary
FragmentCache()
           
 
Method Summary
 void clear()
           
 void cleared()
          Listening to ItemCache
 void cleared(Serializable id)
          Listening to ItemCache
 Fragment get(String id, String format, String lang)
          Look for fragment in cache.
 CacheInfo getCacheInfo()
           
static FragmentCache getInstance()
           
 void notStored(Serializable arg0, Serializable arg1, Long arg2, Long arg3, Serializable arg4)
           
static boolean put(Fragment fragment)
          Store fragment in cache.
 void remove(String mbaseId)
          Remove all fragments belonging to a content Item.
 void stored(Serializable arg0, Serializable arg1, Long arg2, Long arg3, Serializable arg4)
           
 void storeRequested(Serializable arg0, Serializable arg1, Long arg2, Long arg3, Serializable arg4)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static Category log

CACHE_ID

public static final String CACHE_ID
See Also:
Constant Field Values
Constructor Detail

FragmentCache

public FragmentCache()
Method Detail

getInstance

public static FragmentCache getInstance()

get

public Fragment get(String id,
                    String format,
                    String lang)
Look for fragment in cache. If not found, return null.

Parameters:
id - absolute identifier of the fragment.
format - output format.
lang - language tag, which can contain extended fields like "en_UK".
Returns:
fragment content if found, null otherwise.

put

public static boolean put(Fragment fragment)
Store fragment in cache. The cache key is a tuple (id, fmt, lang). The group is the fragment/item id, so all fragments belonging to the same Item are stored in the same group.

Returns:
true if fragment could be stored.

remove

public void remove(String mbaseId)
Remove all fragments belonging to a content Item. They are stored in the same group, referenced by the item's MBaseId.

Specified by:
remove in interface CacheControl
See Also:
CacheControl.remove(java.lang.String)

clear

public void clear()
Specified by:
clear in interface CacheControl
See Also:
CacheControl.clear()

getCacheInfo

public CacheInfo getCacheInfo()
Specified by:
getCacheInfo in interface CacheControl
See Also:
CacheControl.getCacheInfo()

cleared

public void cleared()
Listening to ItemCache

Specified by:
cleared in interface StorageListener
See Also:
StorageListener.cleared()

cleared

public void cleared(Serializable id)
Listening to ItemCache

Specified by:
cleared in interface StorageListener
See Also:
StorageListener.cleared(java.io.Serializable)

notStored

public void notStored(Serializable arg0,
                      Serializable arg1,
                      Long arg2,
                      Long arg3,
                      Serializable arg4)
Specified by:
notStored in interface StorageListener
See Also:
StorageListener.notStored(java.io.Serializable, java.io.Serializable, java.lang.Long, java.lang.Long, java.io.Serializable)

stored

public void stored(Serializable arg0,
                   Serializable arg1,
                   Long arg2,
                   Long arg3,
                   Serializable arg4)
Specified by:
stored in interface StorageListener
See Also:
StorageListener.stored(java.io.Serializable, java.io.Serializable, java.lang.Long, java.lang.Long, java.io.Serializable)

storeRequested

public void storeRequested(Serializable arg0,
                           Serializable arg1,
                           Long arg2,
                           Long arg3,
                           Serializable arg4)
Specified by:
storeRequested in interface StorageListener
See Also:
StorageListener.storeRequested(java.io.Serializable, java.io.Serializable, java.lang.Long, java.lang.Long, java.io.Serializable)