Skip to content

Codefinity-Java/cache-api-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

REST API with Spring Boot and Redis Caching

This project demonstrates a simple RESTful API built using Spring Boot with caching capabilities implemented using Redis. It provides basic CRUD functionality for managing users.

Features

  • RESTful API endpoints for creating, retrieving, and deleting users
  • Data persistence using JPA and an SQL database
  • Redis caching for efficient retrieval of user data

Technologies Used

  • Spring Boot
  • Spring Data JPA
  • Redis for caching
  • MySQL
  • Java 17+

Endpoints

HTTP Method Endpoint Description
GET /api/users/{id} Retrieve a user by their ID (cached).
POST /api/users Create a new user.
DELETE /api/users/{id} Delete a user by their ID (removes from cache).

How Caching Works

The @Cacheable annotation is used to cache the result of the getUserById method. When the method is called with the same ID, the cached result is returned, avoiding unnecessary database queries. The @CacheEvict annotation ensures that the cache is cleared when a user is deleted.

Running the Project

  1. Clone this repository.
  2. Ensure Redis is installed and running locally.
  3. Update the application.properties file with your database and Redis configurations.
  4. Run the application using mvn spring-boot:run or your preferred IDE.
  5. Use tools like Postman or cURL to interact with the API endpoints.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages