Configure the dynamic cache service in cachespec.xml

The dynamic cache service is an in-memory cache system that has disk offload capability. Cacheable objects are defined the cachespec.xml file that is found inside the Web application archive (WAR), Web module WEB-INF directory, or enterprise bean WEB-INF directory. A global cachespec.xml file can also be placed in the application server properties directory, but the recommended method is to place the cache configuration file with the deployment module. There is a sample cache configuration file (cachespec.sample.xml) in the WAS_installdir/properties directory. The cachespec.dtd file is available in the application server properties directory. The following sections detail the steps required to configure dynamic caching in the cachespec.xml file.


Enable the dynamic cache service

In the production environment both the dynamic cache service and servlet caching are enabled, by default.

(Developer)

Note: Servlet caching is disabled in the developer environment. To enable and use servlet caching, see Configure servlet caching.


Defining cache entry elements

The root element of the cachespec.xml file, <cache>, contains <cache-entry> elements. The WebSphere dynamic cache service parses the cachespec.xml file while the server starts, and extracts a set of configuration parameters from each <cache-entry> element.


Defining cache ID generation rules

As the dynamic cache service places objects in the cache, it labels them with unique identifying strings (cache IDs) constructed according to <cache-id> rules specified in the <cache-entry> elements. After an object with a particular cache ID is in the cache, a subsequent request for an object with the same cache ID is served from the cache. The <cache-id> rules define how to construct cache-IDs from information associated with an application server request, including how information might be obtained programmatically from CacheableCommand objects.

The following table lists the request attributes:

Request attributes Description
DC_curr User's preferred currency
DC_lang User's preferred language
DC_porg User's parent organization
DC_cont User's current contract
DC_mg User's explicit member groups
DC_storeId Store identifier
DC_userId User's identifier
s Buyer's eligible contracts (only valid for Supply Chain business model)

The <timeout>,<priority>, and <property> subelements can be used to control cache entry expiry, cache eviction policy, and other generic properties for a cached object with an identifier generated by its enclosing <cache-id>element. For more information about the <cache-id> element, and its subelements, see the topic cachespec.xml. The following <cache-entry>example uses a <cache-id>element to cache results that are created by a JSP and generate a cache ID with two components, "storeId" and "catalogId", obtained from parameters in the request object:


Defining dependency ID and invalidation ID generation rules

Dependency ID elements are used to specify additional cache group identifiers that associate multiple cache entries to the same group identifier.

Dependency IDs are generated by concatenating the dependency ID base string with the values returned by its component elements. If a required component returns a null value, then the entire dependency ID does not generate and is not used. We can validate dependency IDs explicitly through the WebSphere Dynamic Cache API, or use another cache-entry <invalidation> element. Dependency IDs are essential because invalidation cannot occur without them.

Invalidation IDs are used with dependency IDs to remove invalidated objects from the cache.

Invalidation IDs are generated according to rules specified by <invalidation> elements within <cache-entry> elements. When a request that matches a <cache-entry>element is received, its generated invalidation IDs are matched against the dependency IDs previously associated with cached objects. Cached objects with an associated dependency ID that is the same as one of the generated invalidation IDs are invalidated.

Each <cache-entry> element might contain several<invalidation> elements. Each <invalidation> element causes an invalidation ID to be generated when a request that matches its <cache-entry> element is received.

Each invalidation ID is generated by concatenating its invalidation ID base string with the values, each prefixed with a colon (":"), returned by its <component> subelements. If a required component returns a null value, then its part of the generated invalidation ID is discarded.

The following <cache-entry>example defines an <invalidation> element to generate an invalidation ID, "catalogId", when the CatalogUpdateCmdImpl command is run:

In this example, when a request to run the specified command com.ibm.commerce.catalogmangement.commands.CatalogUpdateCmdImpl is received with parameters "storeId=10001&catalogId=10010", the generated invalidation ID is "catalogId:10010". That would cause any cached objects associated with a dependency ID of that value to be invalidated, effectively removing them from the cache.


Related concepts
Caching strategy
Dynamic caching considerations with JSTL


Related tasks
Configure cacheable objects


Related reference
Cache-entry elements