Chapter 2. Embedded caches

Add Data Grid as a dependency to your Java project and use embedded caches that increase application performance and give you capabilities to handle complex use cases.

2.1. Embedded cache tutorials

You can run embedded cache tutorials directly in your IDE or from the command line as follows:

$ mvn -s /path/to/maven-settings.xml clean package exec:exec
Tutorial linkDescription

Distributed caches

Demonstrates how Distributed Caches work.

Replicated caches

Demonstrates how Replicated Caches work.

Invalidated caches

Demonstrates how Invalidated Caches work.

Transactions

Demonstrates how transactions work.

Streams

Demonstrates how Distributed Streams work.

JCache integration

Demonstrates how JCache works.

Functional Maps

Demonstrates how Functional Map API works.

Map API

Demonstrates how the Map API works with Data Grid caches.

Multimap

Demonstrates how to use Multimap.

Queries

Uses Data Grid Query to perform full-text queries on cache values.

Clustered Listeners

Detects when data changes in an embedded cache with Clustered Listeners.

Counters

Demonstrates how to use an embedded Clustered Counter.

Clustered Locks

Demonstrates how to use an embedded Clustered Lock.

Clustered execution

Demonstrates how to use an embedded Clustered Counter.

Data Grid documentation

You can find more resources about embedded caches in our documentation at:

2.2. Kubernetes and Openshift tutorial

This tutorial contains instructions on how to run Infinispan library mode (as a microservice) in Kubernetes/OpenShift.

Prerequisites: Maven and Docker daemon running in the background.

Prerequisites

  • A running Openshift or Kubernetes cluster

Building the tutorial

This tutorial is built using the maven command:

mvn package

Note that target/ directory contains additional directories like docker (with generated Dockerfile) and classes/META-INF/jkube with Kubernetes and OpenShift deployment templates.

Tip

If the Docker Daemon is down, the build will omit processing Dockerfiles. Use docker profile to turn it on manually.

Deploying the tutorial to Kubernetes

This is handle by the JKube maven plugin, just invoke:

mvn k8s:build k8s:push k8s:resource k8s:apply -Doptions.image=<IMAGE_NAME> 1
1
IMAGE_NAME must be replaced with the FQN of the container to deploy to Kubernetes. This container must be created in a repository that you have permissions to push to and is accessible from within your Kubernetes cluster.

Viewing and scaling up

Everything should be up and running at this point. Now login into the OpenShift or Kubernetes cluster and scale the application

kubectl scale --replicas=3  deployment/$(kubectl get rs --namespace=myproject | grep infinispan | awk '{print $1}') --namespace=myproject

Undeploying the tutorial

This is handled by the JKube maven plugin, just invoke:

mvn k8s:undeploy