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.
- 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®.
- 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. TheINFINISPAN_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 theINFINISPAN_HOST
,INFINISPAN_PORT
,INFINISPAN_USER
, andINFINISPAN_PASS
environment variables in addition to theINFINISPAN_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 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 configure.sh to copy the client topology hazelcast.xml
ARG HZ_SESSION_CACHE=client
# Default setting for the verbose option
ARG VERBOSE=false
# Instruct configure.sh to copy the embedded topology hazelcast.xml and set the required system property
#ARG HZ_SESSION_CACHE=embedded
#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
RUN configure.sh