Cache Manager-Application access
From the application, access to the Cache layer is as simple as a single Manager that provides the necessary services.
Class: CacheManager
This is the entry point for accessing the Cache Management layer from within your application. This is created as a singleton class through which all access is managed. As a user of this layer, you can safely invoke the getDataFromCache() API from anywhere within the application. The Cache Management layer takes care of populating or validating the cache prior to returning the cache data to the caller.
The details of the behavior exposed by this class are:
Attribute / Operation | Purpose |
---|---|
static CacheManager getInstance() | This method returns the singleton instance of the CacheManager. |
List getDataFromCache(HttpSession session, String cacheKey) | This method returns the data for the cacheKey provided. In case the cache happens to be a Session cache, then it picks the User information from the Session and appropriately identifies the session specific information for that Cache and returns the information. For an Application Cache, the session can be passed as null. |
void invalidateCache(HttpSession session, String cacheKey) | This method can be used by the developer to clear out a cache. This may be useful for cases where there is an explicit need in the business logic to force reload of a cache. This method will only clear the cache and will not trigger reload of the cache. The cache reload gets triggered only when the next call to getDataFromCache() is invoked. |
void invalidateCache(String cacheKey) | This is a variant of the other invalidateCache having the same functionality. The difference is this version is suitable for application caches while the earlier one is a session cache. |
Class: CacheDataBuilder
This is the base class for all cache handlers. A Cache handler is responsible for the following:
- Getting the data for the cache.
- If the cache is validating, then validating whether the cache is stale (not reload blindly) and informing the Cache Management layer for it to take care of refreshing.
- Validating any configured parameters provided for correctness.
The details of the behavior exposed by this class are as follows:
Attribute or Operation | Purpose |
---|---|
abstract List initializeCache(HashMap params); | This method is triggered by the Cache Management Layer for loading the data of the cache. The params map provided to this handler will typically be empty for an Application Cache. For a session cache, this will provide the reference to the SessionInfo corresponding to the logged in user under the key SESSIONINFO. |
abstract String validateParameters(HashMap params); | This method is triggered by the Cache Management Layer for validating any parameters provided as part of the XML for this handler. |
boolean isCacheUptoDate(); | This method should be overridden by the handler in case it supports the capability to validate the Cache data for staleness. |
HashMap HandlerState; | This attribute maintains the state of the handler. Typically this is used in conjunction with the need to have a validated cache. |
abstract List initializeCache(HashMap params); | This method is triggered by the Cache Management Layer for loading the data of the cache. The params map provided to this handler will typically be empty for an Application Cache. For a session cache, this will provide the reference to the SessionInfo corresponding to the logged in user under the key SESSIONINFO. |
Class: GenericDatabaseCacheDataBuilder
This is a default implementation of the CacheDataBuilder that default fetches the data based on a Database query. This internally uses the Canvas Database Access Framework for triggering a DatabaseRequest with the configured Data Access Locator and Extension provided.
This cache handler supports the following handler parameters –
Parameter Name | Purpose |
---|---|
DATA_ACCESS_MAP_KEY | This is a mandatory parameter that provides the Data Access Map Key of the Data Access Locator. |
DATA_ACCESS_EXTN | This is a mandatory parameter that provides the Extension part of the Data Access Locator. |
Using this as the handler for your cache would mean that there should be a Query configured with the Data Access Locator combination of <DATA_ACCESS_MAP_KEY>SELECT<DATA_ACCESS_EXTN>.