What is Infinispan ? a quick introduction

What is Infinispan ? In a nutshell, Infinispan is an open source data grid platform written in Java which exposes a JSR-107 compatible cache interface in which you can store objects.

There are several use cases for Infinispan: let’s discuss the three most common use cases:

Using Infinispan as a Cache

Firstly, Infinispan can be used as a cache in front of your database, disk-based NoSQL store to offload your DB.

Database offloading is the process of removing or reducing the database load, mainframes which is a common bottleneck of applications.

Often, however, a simple cache isn’t enough – for example if your application is clustered and cache coherency is important to data consistency. A distributed cache like Infinispan can greatly help in such scenarios.

Using Infinispan as Data Store

Infinispan can also be used as a high-performance NoSQL data store. In addition to being in memory, Infinispan can also persist data to a more permanent store. We call this a cache store. Cache stores are pluggable, you can easily write your own, and many already exist for you to use. Learn more about cache stores – and existing implementations you can use today – on the cache stores section of this website.

Using Infinispan to add HA

Another common use case is adding clusterability and high availability to frameworks. You can configure Infinispan to replicate every new object to all nodes (Infinispan instances), which will result in simply maintaining a copy of each object in every node, so that if one of the nodes fails, state is not lost

This is a non-exhaustive list of features of Infinispan:

  • Data partitioning across a cluster
  • Work with domain objects rather than only bytes, arrays, or strings
  • Synchronous and asynchronous operations throughout
  • Distributed ACID transactions
  • Data distribution through the use of a consistent hash algorithm to determine where keys should be located in the cluster
  • Write-through/behind cache store support
  • Eviction support
  • Elastic scaling
  • Multiple access protocols
  • Support for compute grids
  • Persisting state to configurable cache stores

A first taste of Infinispan

Here is now a one minute example to get started with Infinispan.

  1. First, download the latest version from https://infinispan.org/download/

2. Unzip the Infinispan Server to a folder on your hard drive

3. Next, create an user to access the Management console. From the bin folder run:

./cli.sh user create
Specify a username: admin
Set a password for the user: password
Confirm the password for the user: password

4. Then, we will enable the REST Endpoint so that we can fetch some data using cURL. Open the conf/infinispan.xml and edit the endpoints section to include BASIC and DIGEST authentication:

<endpoints socket-binding="default" security-realm="default">
   <rest-connector>
      <!-- Specifies SASL mechanisms to use for authentication. -->
      <authentication mechanisms="DIGEST BASIC"/>
   </rest-connector>
</endpoints>

5. Finally, start the server from the bin folder:

$ ./server.sh

Adding a cache with some Data

To connect to Infinispan Management console, reach http://localhost:11222/ and log in with the user name admin/password:

what is infinispan
Click on Open Console. From there choose to Create Cache:
what is infinispan in a nutshell

Next, add a cache named “democache” using the example Cache template provided:

what can I use infinispan for

Then, add a simple cache entry to your cache:

what is the use of infinispan
Well done. We have just added a cache entry for our first cache. As we have enabled the REST endpoint, we can access our data from any tool like cURL:
curl  -u "admin:password" http://localhost:11222/rest/v2/caches/democache/name

{
   "_type": "string",
   "_value": "Sherlock Holmes"
}

Conclusion

We have just covered what is Infinispan and provided a basic quickstart for it. To continue learning check this resource: Getting Started with Infinispan data grid

Found the article helpful? if so please follow us on Socials