Setting up session caching for applications in containers

The WebSphere® Liberty session caching feature builds on an existing technology called JCache (JSR 107), which provides an API for distributed in-memory caching. You can set up session caching by configuring a JCache provider such as Infinispan or Hazelcast.

Setting up session caching with Infinispan

Infinispan is an open source project that is the basis for Red Hat Data Grid. When you enable Infinispan session caching, the Infinispan client libraries are retrieved from the Infinispan JCACHE (JSR 107) Remote Implementation Maven repository, and the necessary infinispan.client.hotrod.* properties and the WebSphere Liberty server feature sessionCache-1.0 are configured by including the infinispan-client-sessioncache.xml XML snippet.

  1. Set up the Infinispan service.

    Ensure that you have an Infinispan service available in your Kubernetes environment. You can create your Infinispan service by using the Infinispan Operator. The Infinispan Operator Tutorial explains how to get started with Infinispan in Red Hat® OpenShift®.

  2. Install the client JAR files and set the INFINISPAN_SERVICE_NAME environment variable.

    To enable Infinispan in WebSphere Liberty, the container image author can use the provided Dockerfile. This Dockerfile assumes an Infinispan service name of example-infinispan, which is the default that is used in the Infinispan Operator Tutorial. To customize your Infinispan service, see Creating Infinispan Clusters. The INFINISPAN_SERVICE_NAME environment variable must be set at build time as shown in the example Dockerfile, or overridden at image deployment time.

    Tip: If your Infinispan deployment and WebSphere Liberty deployment are in different namespaces or projects, set the INFINISPAN_HOST, INFINISPAN_PORT, INFINISPAN_USER, and INFINISPAN_PASS environment variables in addition to the INFINISPAN_SERVICE_NAME environment variable. Setting these environment variables ensures that the WebSphere Liberty deployment has access to the Infinispan service environment variables it requires.

Setting up session caching with Hazelcast

Hazelcast In-Memory Data Grid is another JCache provider. When you enable Hazelcast session caching, the Hazelcast client libraries are retrieved from the hazelcast/hazelcast container image, and Hazelcast is configured by copying a sample hazelcast.xml. The WebSphere Liberty server feature sessionCache-1.0 is configured by including the XML snippet hazelcast-sessioncache.xml. By default, the Hazelcast Discovery Plugin for Kubernetes automatically discovers its peers within the same Kubernetes namespace. To enable session caching with Hazelcast, the container image author can include the following Dockerfile snippet, and choose from either client/server or embedded topology.
### Hazelcast Session Caching #### 
Copy the Hazelcast libraries from the Hazelcast container image
COPY --from=hazelcast/hazelcast --chown=1001:0 /opt/hazelcast/lib/*.jar /opt/ibm/wlp/usr/shared/resources/hazelcast/

# Instruct to copy the client topology hazelcast.xml

# Default setting for the verbose option

# Instruct to copy the embedded topology hazelcast.xml and set the required system property
#ENV JAVA_TOOL_OPTIONS="-Dhazelcast.jcache.provider.type=server ${JAVA_TOOL_OPTIONS}"

## This script will add the requested XML snippets and grow image to be fit-for-purpose