1. Introduction

Infinispan’s CassandraStore leverages Apache Cassandra’s distributed database architecture to provide a virtually unlimited, horizontally scalable persistent store for Infinispan’s caches.

2. Configuration

In order to use this cache store you need to create an appropriate keyspace on your Cassandra database, or configure the auto-create-keyspace to create it automatically. The following CQL commands show how to configure the keyspace manually (using cqlsh for example):

CQL
CREATE KEYSPACE IF NOT EXISTS Infinispan WITH replication = {'class':'SimpleStrategy', 'replication_factor':1};
CREATE TABLE Infinispan.InfinispanEntries (key blob PRIMARY KEY, value blob, metadata blob);

You then need to add an appropriate cache declaration to your infinispan.xml (or whichever file you use to configure Infinispan):

infinispan.xml
<cache-container default-cache="cassandracache">
    <local-cache name="cassandracache">
        <persistence passivation="false">
            <cassandra-store xmlns="urn:infinispan:config:store:cassandra:8.2" auto-create-keyspace="true" keyspace="Infinispan" entry-table="InfinispanEntries" shared="true">
                <cassandra-server host="127.0.0.1" port="9042" />
                <connection-pool heartbeat-interval-seconds="30" idle-timeout-seconds="120" pool-timeout-millis="5" />
            </cassandra-store>
        </persistence>
    </local-cache>
</cache-container>

It is important that the shared property on the cassandra-store element is set to true because all the Infinispan nodes will share the same Cassandra cluster.

An alternative way to configure the Cassandra cachestore is to use a generic store element with properties. An example configuration with the available properties is shown below: .infinispan.xml

<cache-container default-cache="cassandracache">
    <local-cache name="cassandracache">
        <persistence passivation="false">
            <store class="org.infinispan.persistence.cassandra.CassandraStore" shared="true">
                <property name="autoCreateKeyspace">true</property>
                <property name="keyspace">Infinispan</property>
                <property name="entryTable">InfinispanEntries</property>
                <property name="consistencyLevel">LOCAL_ONE</property>
                <property name="serialConsistencyLevel">SERIAL</property>
                <property name="servers">127.0.0.1[9042],127.0.0.1[9041]</property>
                <property name="connectionPool.heartbeatIntervalSeconds">30</property>
                <property name="connectionPool.idleTimeoutSeconds">120</property>
                <property name="connectionPool.poolTimeoutMillis">5</property>
            </store>
        </persistence>
    </local-cache>
</cache-container>

3. Limitations

The cache store uses Cassandras own expiration mechanisms (time to live = TTL) to handle expiration of entries. Since TTL is specified in seconds, expiration lifespan and maxIdle values are handled only with seconds-precision.

In addition to this, when both lifespan and maxIdle are used, entries in the cache store effectively behave as if their lifespan = maxIdle, due to an existing bug https://issues.jboss.org/browse/ISPN-3202.