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:
$ ./mvnw -s /path/to/maven-settings.xml clean package exec:exec
Tutorial link | Description |
---|---|
Demonstrates how Distributed Caches work. | |
Demonstrates how Replicated Caches work. | |
Demonstrates how Invalidated Caches work. | |
Demonstrates how transactions work. | |
Demonstrates how Distributed Streams work. | |
Demonstrates how JCache works. | |
Demonstrates how Functional Map API works. | |
Demonstrates how the Map API works with Data Grid caches. | |
Demonstrates how to use Multimap. | |
Uses Data Grid Query to perform full-text queries on cache values. | |
Detects when data changes in an embedded cache with Clustered Listeners. | |
Demonstrates how to use an embedded Clustered Counter. | |
Demonstrates how to use an embedded Clustered Lock. | |
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:
./mvnw package
Note that target/
directory contains additional directories like docker
(with generated Dockerfile) and classes/META-INF/jkube
with Kubernetes and OpenShift deployment templates.
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