Defining custom caches in the WebSphere Application Server configuration
To be able to use DynaCache APIs to operate a cache, the cache first needs to be declared in the WebSphere Application Server configuration.
The steps differ depending on the server in use:
- Transaction server container: Runtime Configuration
- WebSphere Application Server V8.5.5 Liberty-based containers
- Development Environment
Transaction server container: Runtime Configuration
run add-objectcache jndiName cacheSize NONE sizeMB
For
example:run add-objectcache “services/cache/CustomCache1” 2000 NONE 100
Caches are created by default using the HCL Cache provider. If a different cache provider, such as DynaCache or WebSphere Extreme Scale, is required, use the set-cache-provider run engine command to reconfigure the cache.
WebSphere Application Server V8.5.5 Liberty-based containers
- 1. Create a custom customcache.xml file under the
configDropins/overrides
directory.
/opt/WebSphere/Liberty/usr/servers/default/configDropins/overrides/customcache.xml
- 2. Define the new caches within the XML as
follows.
<?xml version="1.0" encoding="UTF-8"?> <server> <distributedMap id="services/cache/CustomCache1" memorySizeInEntries="2000" memorySizeInMB="100" cacheProviderName="hcl-cache"/> </server>
Development Environment
Custom caches can be defined for each server type. For WebSphere Application Server V8.5.5 Liberty servers, or Liberty-based containers, follow the runtime steps as outlined under WebSphere Application Server V8.5.5 Liberty-based containers.
For the Transaction server running under the HCL Commerce test environment, custom caches can be added using the WebSphere Application Server Administrative Console:
- In the WebSphere Application Server Administrative Console, click .
- Enter the required display name for the resource in the Name field.
-
Enter the resource's JNDI name and the JNDI description.
For example, for a custom cache value can use this format:services/cache/MyCustomCache
- Use HCL Cache as the cache-provider.
- Set a cache size of 2000 entries; if necessary, this value can be increased or decreased depending on cache utilization.
Click Apply or OK.