CRM and CX Blogs by SAP
Stay up-to-date on the latest developments and product news about intelligent customer experience and CRM technologies through blog posts from SAP experts.
cancel
Showing results for 
Search instead for 
Did you mean: 
WolfgangSattler
Advisor
Advisor
0 Kudos

In this blog I will give a short overview about the WCEM cache functionality, because this documentation is not yet part of the dev and extension guide of release 2.0 and 3.0.

Overview

The WCEM framework provides access to cache functionality, which can be used to store any kind of data.

You can choose between different cache engines. The following implementations are available:

  • Default: CML cache provided by SAP NetWeaver 
  • Custom WCEM implementation (in WCEM standard, used only for internal integration tests) 
  • Mock implementation (in WCEM standard, used only for internal Java unit tests)

Cache Regions and Attributes 

The cache is divided into regions. Each region represents an individual cache, and the region name is used to distinguish between caches. If you need your own cache, you have to add a new region, together with attributes. These attributes define how the cache handles objects that are cached in the region (be aware that not all attributes are supported in each implementation).

The following attributes define the eviction policy within a region (only supported by the CML implementation): 

  • evictionCountStart (Default value: 750) 
  • evictionCountUpperLimit (Default value: 950) 
  • evictionCountCriticalLimit (Default value: 1000)

Example:

  <region name="myRegion" countStart="750" countUpper="950" countCritical="1000">  

This means that the eviction of the objects starts when there are 750 objects in the cache region. At 950 objects, the eviction policy starts evicting an object at each put. At 1000 objects, the critical size of the cache is reached and the benefit of the cache is not clear. Idle time and time-to-live (TTL) are explained above.

At this point in time we don't support time dependent cache entries.

Defining Cache Regions 

The configuration of a cache region can be performed using the cache-config.xml file. Cache regions, which are declared in the cache-config.xml file, are initialized when the application is started by the framework.


Example for defining cache regions within cache-config.xml:

  <cache> 
     <regions> 
          <region name="JCO" loaderClassName="com.sap.wec.tc.core.common.cache.JCoFunctionLoader"
                     descr="Used to cache SAP Java Connector calls to the SAP system"
                     countStart="750" countUpper="950" countCritical="1000" /> 
         <region name="UICOMP" descr="Used to cache configuration data and other settings for ui components" 
                     countStart="750" countUpper="950" countCritical="1000"
         </region> 
      </regions> 
</cache> 

Accessing Cache Regions 

The access to the cache is enabled by using a cache access object (CacheAccess). You can get access to your cache region by using the singleton CacheProvider (see example below). The access object provides methods to add, retrieve, invalidate, or remove objects from the cache.

Example: Getting access to region 'CacheRegion'

  ...  // Get access to cache region 'CacheRegion'  
CacheAccess access = CacheProvider.getInstance().getCacheAccess("CacheRegion");   

// Put object in to cache 
String testKey = "key1"
Object testPut = new Object(); 
access.put(testKey, testPut);  ...   
// Get object from cache 
Object getObject = access.get("key1");  ... 

Defining/Implementing Cache Loader Classes 

Additionally, an abstract class CacheLoader is available, which can be used to create cached objects. This class can be extended to write a custom cache loader. The class JCoFunctionLoader is available as a cache loader for JCo functions.

Example:

 CacheAccess cacheAccess = null
try {
   cacheAccess = CacheProvider.getInstance().getCacheAccess(CACHE_REGION_NAME);

catch (WCFCacheException ex) { 
   / / region not available \-> standard execute 
   
client.execute(func); 
  return;
}

JCO.Function cachedFunc = (JCO.Function) cacheAccess.get(key.toString(), 
new JCoFunctionLoader.JCoFunctionAttr(client, func)); 

Cache Registration 

Each cache-config file has to be maintained in the metadata.xml file.

<config-file namespace="sap" part="bo" type="cache-config">cache-config.xml</config-file>

Place the cache-config.xml file into the path src\<your namespace>\<your module>\bo\cache-config.xml in your module BO part.

The cache-config.xml file should contain only the definition of the cache region that your own module uses. The cache-config file from other modules, including the system module, will be merged together.

Further information can be found in the Configuration Management documentation.

Enhanced Features

Changing the Cache Implementation

To determine which implementation is used, a parameter is added to the initialization tag within file bootstrap-config.xml for class "com.sap.wec.tc.core.common.cache.CacheInitHandler":

 <initialization name="CacheInitHandler" className="com.sap.wec.tc.core.common.cache.CacheInitHandler">  
    <param name="cacheEngine" value="com.sap.wec.tc.core.common.cache.CMLCacheEngineImpl"/> 
</initialization> 
1 Comment