JCache Session Persistence1.0
This feature enables persistence of HTTP sessions using JCache. Persisting HTTP session data using JCache allows for high performance HTTP session persistence without the use of a relational database. Failover of HTTP sessions can be achieved by configuring multiple servers to persist data to the same location.
Enabling this feature
To enable the JCache Session Persistence 1.0 feature, add the following element declaration into your server.xml
file, inside the featureManager
element:
<feature>sessionCache-1.0</feature>
Examples
Persist HTTP session data with Hazelcast as the JCache provider
The sessionCache
feature does not include a JCache implementation, so you must pick one and reference it as a library in your server.xml
file. You must define a location for the implementation files with the library
element and reference that library by specifying the jCacheLibraryRef
attribute for the cachingProvider
element.
In the following example, Hazelcast is specified as the JCache implementation. The library
element specifies that Hazelcast, which is located in the hazelcast.jar
library, must be used as the JCache provider:
<library id="JCacheLib">
<file name="${shared.resource.dir}/hazelcast/hazelcast.jar"/>
</library>
<httpSessionCache cacheManagerRef="CacheManager"/>
<cacheManager id="CacheManager" >
<cachingProvider jCacheLibraryRef="JCacheLib" />
</cacheManager>
Customizing the JCache implementation
You can provide an optional configuration file to customize how your JCache implementation manages HTTP session caching. To specify the file location, use the uri
attribute for the cacheManager
element. In the following example, the uri
attribute specifies the location of a Hazelcast configuration file:
<library id="JCacheLib">
<file name="${shared.resource.dir}/hazelcast/hazelcast.jar"/>
</library>
<httpSessionCache cacheManagerRef="CacheManager"/>
<cacheManager id="CacheManager"
uri="file:${shared.resource.dir}/hazelcast/hazelcast.xml">
<cachingProvider jCacheLibraryRef="JCacheLib" />
</cacheManager>
For more information, see Distributed session caching.
Specify JCache vendor-specific properties
In the following example, Open Liberty is configured to access cached HTTP session data from a remote Infinispan server in client/server
mode on OpenShift. Vendor-specific Infinispan properties are passed to the JCache implementation in the properties
element:
<library id="InfinispanLib">
<fileset dir="${shared.resource.dir}/infinispan" includes="*.jar"/>
</library>
<httpSessionCache cacheManagerRef="CacheManager"/>
<cacheManager id="CacheManager">
<properties
infinispan.client.hotrod.server_list="infinispan-server:11222"
infinispan.client.hotrod.auth_username="sampleUser"
infinispan.client.hotrod.auth_password="samplePassword"
infinispan.client.hotrod.auth_realm="default"
infinispan.client.hotrod.sasl_mechanism="PLAIN"
infinispan.client.hotrod.java_serial_whitelist=".*"
infinispan.client.hotrod.marshaller=
"org.infinispan.commons.marshall.JavaSerializationMarshaller"/>
<cachingProvider jCacheLibraryRef="InfinispanLib" />
</cacheManager>
For more information, see Configuring Infinispan as a JCache provider.