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.
- 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
- Spring Boot
- Spring Data JPA
- Redis for caching
- MySQL
- Java 17+
| 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). |
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.
- Clone this repository.
- Ensure Redis is installed and running locally.
- Update the application.properties file with your database and Redis configurations.
- Run the application using
mvn spring-boot:runor your preferred IDE. - Use tools like Postman or cURL to interact with the API endpoints.