cache Posts

Creating a Simple Spring Boot @Cacheable Cache using JBoss DataGrid on top of Openshift

Several days ago, one of my team member were asking me on how to connect Spring Boot to JBoss Datagrid as its primary cache server. Since we are using Openshift, im using Openshift template “Red Hat JBoss Data Grid 7.2 (Ephemeral, no https)” as base image deployment.

First we need to create instance of Datagrid on Openshift,

Create our cache name,

And finally, we can see our JBoss Datagrid endpoint here, and fyi we are using HotRod protocol to connect to JDG so our endpoint name should be “jdg-datagrid-app-01-hotrod” with port “11333”.

Mybatis recently introduce a new caching mechanism using Redis (http://mybatis.github.io/redis-cache/index.html), and in this tutorial i’m trying to create a simple demonstration for it. MyBatis’ Redis caching is a little bit different with other MyBatis’ caching provider, such as EhCache or OsCache because you need to install Redis server before using it.

Because Redis project does not officially support Windows and i need Redis to run as a windows service so im downloading redis-service.exe from this url (https://github.com/rgl/redis/downloads), install and run it. You can see Redis is running on port 6379.

Because MyBatis Redis Cache hasnt available on Maven repository, so next step is download MyBatis Redis Cache project from github (https://github.com/mybatis/redis-cache), build it into jar and install it manually into our pom.xml file from local folder.

Okay, so here is my pom.xml file, you can see im manually installing mybatis-redis from local repository,

On this article, im trying to create a simple java app that will hold a value that have an expiration time. I usually use this for handling request session or to hold a value that have a time limitation. Btw, i’m using EhCache for handling expiration time.