This is a small Spring Boot application that utilizes Redis for caching layer. Under the hood, the application sends
requests to the public API http://jsonplaceholder.typicode.com, and it caches
the data for the subsequent requests.
For example, when we send a GET request to
http://localhost:8080/posts/{id}
basically it checks the Redis Cache if it has a key which is a string of the id of the Post. If indeed, there is such a key, it returns the value of that key. In our situation is a string of the following JSON object,
{
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
}
On the other hand, if the Redis cache does not have the key (which this is the case for the first time the application starts), it sends a GET request to
http://jsonplaceholder.typicode.com/posts/1
and stores the value for the subsequent calls.
In each request, we are calculating the elapsed time. For HTTP calls we get a time of some hundreds ms. However, with Redis those calls are less than 3ms.
In order to run this application you will need Docker and executing the commands
./gradlew clean build
docker compose build
docker compose up
Here you can find a tutorial about Docker Compose.