planetj.dataengine.cache
Class CacheManager

java.lang.Object
  |
  +--planetj.dataengine.cache.CacheManager

public class CacheManager
extends Object

Manages all of the DataEngine's caches.


Field Summary
static int CACHING_OFF
          Completely disables caching.
static short CLEAR_ON_UPDATES
          An update, delete, or insert will remove all RowCollections retrieved from the affected table from the cache.
static boolean cTrackCache
          Flag to indicate if cache tracking should be done.
static boolean cWriteCacheToFile
          Flag to indicate if cache tracking should be written to a file.
static short IGNORE_UPDATES
          Updates, inserts, and deletes do not affect the cache
static byte SMART_CACHING_COMPLETE
          Enable smart caching across all aliases
static byte SMART_CACHING_OFF
          Don't use smart caching
static byte SMART_CACHING_PER_ALIAS
          Enable smart caching only within the same alias
static int SYSTEM_LEVEL_CACHE
          Uses a single cache for each system
 
Method Summary
 void clearAll()
          Removes all entries from all caches.
 RowCollection get(SQLContext key)
          Gets a RowCollection out of the cache, based on the SQLContext.
 Map getAllCaches()
          Returns a Map containing all the caches being managed.
 DataEngineCache getCache(SQLContext context)
          Gets the appropriate cache for the SQLContext.
 int getCachingLevel()
          Gets the caching level.
 long getEstimatedSize()
          Gets the estimated number of bytes of all field values take up in every RowCollection in cache.
 int getGlobalTimeout()
          Gets the timeout value (in seconds) for all caches.
static CacheManager getInstance()
          Gets the CacheManager instance.
 byte getSmartCachingLevel()
          Gets the smart caching level
 short getUpdatePolicy()
          Gets the update policy.
static boolean isCacheTrackingOn()
          Check to see if caching should be tracked.
static boolean isCacheTrackingWrittenToFile()
          Check to see if cache tracking should be written to a file.
 void put(SQLContext key, RowCollection results)
          Puts a RowCollection in the cache, keyed by the SQLContext.
 RowCollection remove(SQLContext key)
          Removes a RowCollection from the cache, based on the SQLContext.
 void rowAltered(SQLContext context, ExecutingContext ec, long timestamp)
          This method is invoked when a single row is deleted, inserted, or updated.
static void setCacheTrackingOff()
          Turn cache tracking off.
static void setCacheTrackingOn()
          Turn cache tracking on.
static void setCacheTrackingTime(long period)
          Set the time period to which cache tracking is to be run
static void setCacheTrackingWrittenToFileOff()
          Turn cache tracking written to file off.
static void setCacheTrackingWrittenToFileOn()
          Turn cache tracking written to file on.
 void setCachingLevel(int cacheLevel)
          Sets the caching level.
 void setGlobalTimeout(int seconds)
          Sets the timeout value (in seconds) for all caches.
static void setInstance(CacheManager instance)
          Sets the CacheManager instance.
 void setSmartCachingLevel(byte smartCaching)
          Sets the smart caching level
 void setUpdatePolicy(short pUpdatePolicy)
          Sets the update policy.
static CacheManager singleton()
          Gets the CacheManager instance.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CACHING_OFF

public static final int CACHING_OFF
Completely disables caching.

See Also:
Constant Field Values

cTrackCache

public static boolean cTrackCache
Flag to indicate if cache tracking should be done. By default, nothing is tracked.


cWriteCacheToFile

public static boolean cWriteCacheToFile
Flag to indicate if cache tracking should be written to a file. By default, nothing is written to a file.


SYSTEM_LEVEL_CACHE

public static final int SYSTEM_LEVEL_CACHE
Uses a single cache for each system

See Also:
Constant Field Values

IGNORE_UPDATES

public static final short IGNORE_UPDATES
Updates, inserts, and deletes do not affect the cache

See Also:
Constant Field Values

CLEAR_ON_UPDATES

public static final short CLEAR_ON_UPDATES
An update, delete, or insert will remove all RowCollections retrieved from the affected table from the cache.

See Also:
Constant Field Values

SMART_CACHING_OFF

public static final byte SMART_CACHING_OFF
Don't use smart caching

See Also:
Constant Field Values

SMART_CACHING_PER_ALIAS

public static final byte SMART_CACHING_PER_ALIAS
Enable smart caching only within the same alias

See Also:
Constant Field Values

SMART_CACHING_COMPLETE

public static final byte SMART_CACHING_COMPLETE
Enable smart caching across all aliases

See Also:
Constant Field Values
Method Detail

clearAll

public void clearAll()
Removes all entries from all caches. Use caution when invoking this method.


get

public RowCollection get(SQLContext key)
                  throws DataEngineException
Gets a RowCollection out of the cache, based on the SQLContext.

Parameters:
key - The SQLContext, which is the RowCollection's key
Returns:
The RowCollection in the cache which corresponds to the SQLContext, or null if no such RowCollection exists.
DataEngineException

getAllCaches

public Map getAllCaches()
Returns a Map containing all the caches being managed. The Map is for reading purposes only, and cannot be altered. In the Map, DataEngineCache objects are keyed by their system aliases


getCache

public DataEngineCache getCache(SQLContext context)
                         throws DataEngineException
Gets the appropriate cache for the SQLContext. Right now, only a single cache per system is supported, but that may change in the future.

DataEngineException

getCachingLevel

public final int getCachingLevel()
Gets the caching level.

Returns:
One of the constants such as CACHING_OFF or SINGLE_CACHE describing what level of caching will be used.

getEstimatedSize

public long getEstimatedSize()
Gets the estimated number of bytes of all field values take up in every RowCollection in cache.


getGlobalTimeout

public int getGlobalTimeout()
Gets the timeout value (in seconds) for all caches. After they are created, caches will start out with this timeout value


getInstance

public static final CacheManager getInstance()
Gets the CacheManager instance.


getSmartCachingLevel

public byte getSmartCachingLevel()
Gets the smart caching level


getUpdatePolicy

public final short getUpdatePolicy()
Gets the update policy.

Returns:
One of the constants such as IGNORE_UPDATESor CLEAR_ON_UPDATES (the default) describing what the update policy will be

isCacheTrackingOn

public static boolean isCacheTrackingOn()
Check to see if caching should be tracked.


isCacheTrackingWrittenToFile

public static boolean isCacheTrackingWrittenToFile()
Check to see if cache tracking should be written to a file.


put

public void put(SQLContext key,
                RowCollection results)
         throws DataEngineException
Puts a RowCollection in the cache, keyed by the SQLContext.

Parameters:
key - The SQLContext, which is the RowCollection's key
DataEngineException

remove

public RowCollection remove(SQLContext key)
                     throws DataEngineException
Removes a RowCollection from the cache, based on the SQLContext.

Parameters:
key - The SQLContext, which is the RowCollection's key
Returns:
The RowCollection in the cache which corresponds to the SQLContext, or null if no such RowCollection exists.
DataEngineException

rowAltered

public void rowAltered(SQLContext context,
                       ExecutingContext ec,
                       long timestamp)
                throws CMException
This method is invoked when a single row is deleted, inserted, or updated. RowCollections are then notified so they can take appropriate action

Parameters:
context - The SQLContext containing the alteration information
ec - The current executing context
timestamp - The time associated with the alteration
CMException

setCachingLevel

public void setCachingLevel(int cacheLevel)
Sets the caching level.

Parameters:
cacheLevel - One of the constants such as CACHING_OFF or SYSTEM_LEVEL_CACHE describing what level of caching will be used.

setCacheTrackingOff

public static void setCacheTrackingOff()
Turn cache tracking off.


setCacheTrackingOn

public static void setCacheTrackingOn()
Turn cache tracking on.


setCacheTrackingTime

public static void setCacheTrackingTime(long period)
Set the time period to which cache tracking is to be run


setCacheTrackingWrittenToFileOn

public static void setCacheTrackingWrittenToFileOn()
Turn cache tracking written to file on.


setCacheTrackingWrittenToFileOff

public static void setCacheTrackingWrittenToFileOff()
Turn cache tracking written to file off.


setGlobalTimeout

public void setGlobalTimeout(int seconds)
Sets the timeout value (in seconds) for all caches. After they are created, caches will start out with this timeout value. A negative value indicates that items should never expire from the cache.


setInstance

public static void setInstance(CacheManager instance)
Sets the CacheManager instance. Invoke this method only if you want to use a subclass of CacheManager instead of the default implementation.


setSmartCachingLevel

public void setSmartCachingLevel(byte smartCaching)
Sets the smart caching level


setUpdatePolicy

public void setUpdatePolicy(short pUpdatePolicy)
Sets the update policy.

Parameters:
pUpdatePolicy - One of the constants such as IGNORE_UPDATES (the default) or CLEAR_ON_UPDATES describing what the update policy will be

singleton

public static final CacheManager singleton()
Gets the CacheManager instance.