public abstract class

CacheBase

extends Object
implements Cache
java.lang.Object
   ↳ com.microstrategy.utils.cache.CacheBase
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Base class for caches.

Summary

Constants
int DEFAULT_FILE_REFRESH_TIME Refresh time constant indicating that default file refreshing time from the CacheRegistry shall be used for this cache.
int DEFAULT_REFRESH_TIME Refresh time constant indicating that default refresh time from the CacheRegistry shall be used for this cache.
int DEFAULT_STATISTIC_TIME Statistic time constant indicating that default statistic time from the CacheRegistry shall be used for this cache.
int DEFAULT_SYS_TIMEOUT
int DEFAULT_USER_TIMEOUT Timeout constant indicating that default timeout value from the CacheRegistry shall be used for this cache.
int NO_REFRESH Refresh time constant indicating that cache members are never automatically reloaded.
int NO_STATISTIC Statistic time constant indicating that cache shall not automatically log statistic.
int NO_TIMEOUT Timeout constant indicating that cache members shall never timeout.
Fields
public static final Object NO_KEY

This constant is returned from getKey(CacheHint) if the hint object does not contain enough information to build the key but it is still possible to load the object from the persistent storage.

public String alias Cache alias.
Protected Constructors
CacheBase(String pName, boolean useSoftReferences, int pTimeout, int pRefreshTime)
Constructs a cache with specified name and soft reference flag.
CacheBase(String pName, boolean useSoftReferences, int pTimeout, int pRefreshTime, String pAlias)
Public Methods
synchronized void clear()
Clears the cache - all entries are removed.
void close()
Un-register cache from the cache registry.
boolean contains(CacheHint hint)
void delete(CacheHint hint)
Removes object from the cache and persistent storage
Object get(CacheHint hint)
Finds and returns cached object based on the hint.
String getName()
Returns cache name.
synchronized int getRefreshTime()
Returns cache refresh time in seconds.
synchronized int getStatisticTime()
Returns the statistic frequency in seconds.
synchronized int getTimeout()
Returns cache timeout in seconds.
void logStatistic()
Writes cache statistic message to the log.
void onHintClose(CacheHint hint)
This method is supposed to be called by the hint object when it is closed.
void put(CacheHint hint, Object ob)
Puts the object in the cache.
Object refresh(CacheHint hint)
Re-loads object from the persistent storage
void remove(CacheHint hint)
Removes an object from the cache.
void save(CacheHint hint, Object ob)
Puts the object in the cache and stores it in the memory.
synchronized void setRefreshTime(int value)
Sets cache refresh time in seconds.
synchronized void setStatisticTime(int value)
Sets the statistic frequency in seconds.
synchronized void setTimeout(int value)
Sets cache timeout in seconds.
synchronized int size()
Returns cache size.
Protected Methods
boolean canUpdate(CacheHint hint)
Overridable.
synchronized void configure(Properties prop)
abstract Object getKey(CacheHint hint)
Overridable.
abstract Object load(CacheHint hint)
Overridable.
void onTimer()
This method is periodically called by the cache registry.
Object reLoad(CacheHint hint, Object ob)
Overridable.
void store(CacheHint hint, Object ob)
Overridable.
void unLoad(CacheHint hint)
Overridable.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.microstrategy.utils.cache.Cache

Constants

public static final int DEFAULT_FILE_REFRESH_TIME

Refresh time constant indicating that default file refreshing time from the CacheRegistry shall be used for this cache.

Constant Value: -3 (0xfffffffd)

public static final int DEFAULT_REFRESH_TIME

Refresh time constant indicating that default refresh time from the CacheRegistry shall be used for this cache.

Constant Value: -2 (0xfffffffe)

public static final int DEFAULT_STATISTIC_TIME

Statistic time constant indicating that default statistic time from the CacheRegistry shall be used for this cache.

Constant Value: -2 (0xfffffffe)

public static final int DEFAULT_SYS_TIMEOUT

Constant Value: -3 (0xfffffffd)

public static final int DEFAULT_USER_TIMEOUT

Timeout constant indicating that default timeout value from the CacheRegistry shall be used for this cache.

Constant Value: -2 (0xfffffffe)

public static final int NO_REFRESH

Refresh time constant indicating that cache members are never automatically reloaded.

Constant Value: -1 (0xffffffff)

public static final int NO_STATISTIC

Statistic time constant indicating that cache shall not automatically log statistic.

Constant Value: -1 (0xffffffff)

public static final int NO_TIMEOUT

Timeout constant indicating that cache members shall never timeout.

Constant Value: -1 (0xffffffff)

Fields

public static final Object NO_KEY

This constant is returned from getKey(CacheHint) if the hint object does not contain enough information to build the key but it is still possible to load the object from the persistent storage. For example, if the WebIServerSession object contains the session ID, but does not contain either server or project name makes it impossible to cache the corresponding project-level objects but it is possible to load them.

Whenever the cache receives this constant it will always invoke load(CacheHint), i.e. effectively bypassing the cache.

public String alias

Cache alias. Short version of name, used for things like state persistence. Must be unique within application.

Protected Constructors

protected CacheBase (String pName, boolean useSoftReferences, int pTimeout, int pRefreshTime)

Constructs a cache with specified name and soft reference flag.

Parameters
pName cache name
useSoftReferences controls whether hard or soft references shall be used between proxies and cached objects.
Throws
IllegalArgumentException if the cache with specified name already exosts/

protected CacheBase (String pName, boolean useSoftReferences, int pTimeout, int pRefreshTime, String pAlias)

Throws
IllegalArgumentException

Public Methods

public synchronized void clear ()

Clears the cache - all entries are removed.

See Also

public void close ()

Un-register cache from the cache registry. Cache shall not be used after this call.

public boolean contains (CacheHint hint)

public void delete (CacheHint hint)

Removes object from the cache and persistent storage

Parameters
hint the hint object.

public Object get (CacheHint hint)

Finds and returns cached object based on the hint. If object does not exists in the memory it will be loaded from the persistent memory. Returns null if object does not exists in persistent memory either.

Parameters
hint the hint object.
Returns
  • cached object.

public String getName ()

Returns cache name.

Returns
  • cache name.

public synchronized int getRefreshTime ()

Returns cache refresh time in seconds. This property determines the time interval between consecutive automatic re-loads of cached objects.

Returns
  • refresh time in seconds.

public synchronized int getStatisticTime ()

Returns the statistic frequency in seconds.

Returns
  • statistic frequency in seconds..

public synchronized int getTimeout ()

Returns cache timeout in seconds. This property determines for how long cached object can remain in memory without being used.

Returns
  • timeout in seconds.

public void logStatistic ()

Writes cache statistic message to the log. The message level is INFO. It contains the following information:

Get count-Total number of get requests processed by the cache.
Load count-Total number of load/reload operations performed by the cache.
Hit rate-The percentage of get requests satisfied from the memory to all get requests
GC Count-Total number of soft-referenced cached objects removed by the Garbage Collector
GC rate-The percentage of load/reload operations caused by the GC to all load/reload operations

public void onHintClose (CacheHint hint)

This method is supposed to be called by the hint object when it is closed. Cache implementations shall use this call to perform proper cache cleanup.

Parameters
hint the hint object.

public void put (CacheHint hint, Object ob)

Puts the object in the cache. If cache already contains object corresponding to the specified hint it will be replaced with the new one.

Parameters
hint the hint object.
ob object to be cached

public Object refresh (CacheHint hint)

Re-loads object from the persistent storage

Parameters
hint the hint object.
Returns
  • cached object. Different cache implementations can either re-load data in the existing object or create a new one.

public void remove (CacheHint hint)

Removes an object from the cache.

Parameters
hint the hint object.

public void save (CacheHint hint, Object ob)

Puts the object in the cache and stores it in the memory. Normally this method will be called after application obtained an object from the cache and modified it. But it is also possible to use this method to replace cached object with another one or to add to the cache and to the persistent storage a new object.

Parameters
hint the hint object.
ob object to be cached

public synchronized void setRefreshTime (int value)

Sets cache refresh time in seconds. This property determins time interval between consequtive automatic re-loads of cached objects.

Parameters
value refresh time in seconds.

public synchronized void setStatisticTime (int value)

Sets the statistic frequency in seconds. Notice that because the statistic is logged during onTimer event it will never be logged more often then CacheRegistry.cleanupTime value regardless of this property value.

Parameters
value log frequency in seconds.

public synchronized void setTimeout (int value)

Sets cache timeout in seconds. This property determines for how long cached object can remain in memory without being used.

Parameters
value timeout in seconds.

public synchronized int size ()

Returns cache size.

Returns
  • cache size.

Protected Methods

protected boolean canUpdate (CacheHint hint)

Overridable. Returns true if the hint allows updates. Default implementation always returns true.

Parameters
hint the hint object.
Returns
  • true if the hint allows updates.

protected synchronized void configure (Properties prop)

protected abstract Object getKey (CacheHint hint)

Overridable. Extracts from the hint object the key that shall be used to identify the cached object.

Parameters
hint the hint object.
Returns
  • the key
Throws
CacheException if somethig gos wrong.

protected abstract Object load (CacheHint hint)

Overridable. Creates a new cached object instance and populates it with data from the persistent storage. In case the object not found in the persistent storage the implementation can return either null or a dummy object.

Parameters
hint the hint object.
Returns
  • the object or null.
Throws
CacheException if somethig gos wrong.

protected void onTimer ()

This method is periodically called by the cache registry. It loops through cached objects and removes not-used ones.

protected Object reLoad (CacheHint hint, Object ob)

Overridable. Re-populates cached object with data from persistent storage. Implementation of this method can re-load the object “in-place” or it can create another object.

Parameters
hint the hint object.
Returns
  • the object or null.
Throws
CacheException if somethig gos wrong.

protected void store (CacheHint hint, Object ob)

Overridable. Saves cached object in the persistent storage.

Parameters
hint the hint object.
ob the object to save.
Throws
CacheException if somethig gos wrong.

protected void unLoad (CacheHint hint)

Overridable. Removes object from the persistent storage

Parameters
hint the hint object.
Throws
CacheException if somethig gos wrong.