/spring-caching-demo

Demo for caching abstractions in Spring Framework

Spring Caching Abstraction Demo

This is a demo application to show the caching abstraction feature in Spring framework. The application uses a memory based, Redis and Gemfire as the Cache implementations.

Details of the application

The application exposes an endpoint which takes a request of the following form using cURL:

curl -X "POST" "http://localhost:8080/handle" \
     -H "Accept: application/json" \
     -H "Content-Type: application/json" \
     -d $'{
	"id": "200",
	"payload": "sample data",
	"delay": "3000",
	"fail": false
}' -w "\n%{time_connect}:%{time_starttransfer}:%{time_total}\n"

The behavior expected is that the first response is delayed by the "delay" parameter in milliseconds specified in the request, and the subsequent requests should be very quick - the response is cached using the "id" parameter specified in the body of the request.

Testing with an in-memory cache implementation

Start the application using the following command:

./gradlew clean bootRun

Testing with a Redis Store

Ensure that Redis is running, or start it the following way:

redis-server

Connect to Redis using cli:

redis-cli

# List keys
$ keys *

Start the application using "redis" Spring profile the following way:

./gradlew clean bootRun -Dspring.profiles.active=redis

After running the curl command a few times, validate the content in redis

redis-cli

# List keys
$ keys *

Testing with Gemfire

Ensure that Gemfire is started up locally the following way:

gfsh

# start locator
gfsh> start locator --name=locator1

# Set server to understand pdx serializable format
gfsh> configure pdx --read-serialized=true

# start server
gfsh> start server --name=server1

# create region
gfsh> create region --name=messages --type=PARTITION_REDUNDANT --entry-idle-time-expiration=500 --entry-idle-time-expiration-action=INVALIDATE --enable-statistics=true

Start the application using "pcc" Spring profile the following way:

./gradlew clean bootRun -Dspring.profiles.active=cloud,pcc

After running the curl command a few times, validate that the content shows up in gemfire

gfsh>query --query="select * from /messages"