Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hardiksinghbehl/redis-caching-java-spring-boot
Backend application leveraging redis cache to reduce network calls and improve latency.
https://github.com/hardiksinghbehl/redis-caching-java-spring-boot
caching java redis-cache spring-boot spring-boot-cache spring-boot-redis testcontainers
Last synced: 21 days ago
JSON representation
Backend application leveraging redis cache to reduce network calls and improve latency.
- Host: GitHub
- URL: https://github.com/hardiksinghbehl/redis-caching-java-spring-boot
- Owner: hardikSinghBehl
- Created: 2021-07-03T02:23:53.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-12-01T08:46:44.000Z (about 1 year ago)
- Last Synced: 2024-05-10T18:57:45.255Z (8 months ago)
- Topics: caching, java, redis-cache, spring-boot, spring-boot-cache, spring-boot-redis, testcontainers
- Language: Java
- Homepage:
- Size: 188 KB
- Stars: 24
- Watchers: 2
- Forks: 16
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Redis Powered Caching in Java Spring Boot
##### A reference proof-of-concept that leverages caching to reduce network calls and improve latency.---
### Overview
* Database tables and their corresponding initial data are established using [Flyway migration scripts](https://github.com/hardikSinghBehl/redis-caching-java-spring-boot/tree/main/src/main/resources/db/migration).
* The application primarily revolves around the below database entities
* master_houses
* wizards
* The `wizards` entity has a Many-to-One relationship with `master_houses`. This [database diagram](https://github.com/hardikSinghBehl/redis-caching-java-spring-boot/blob/main/docs/database_diagram.png) can be referenced for more information.
* The responsibility of connecting to the provisioned cache instance as configured in the `application.yml` file is managed by [RedisConfiguration.java](https://github.com/hardikSinghBehl/redis-caching-java-spring-boot/blob/main/src/main/java/com/behl/cachetropolis/configuration/RedisConfiguration.java).
* The [service layer](https://github.com/hardikSinghBehl/redis-caching-java-spring-boot/tree/main/src/main/java/com/behl/cachetropolis/service) of the application caches the list of wizards corresponding to a particular house where house ID is kept as the cache key. The stored key is removed from the cache when any wizard record is added, updated, or removed from that particular house to maintain strong read consistency.
* The above approach is followed for individual wizard records as well, utilizing the wizard ID as the cache key.### Testing
Testcontainers have been leveraged to test the caching mechanism within the application. Scenarios of cache hit, cache invalidation, cache updation and data consistency has been tested in the service layer test classes listed below:
* [WizardServiceTest.java](https://github.com/hardikSinghBehl/redis-caching-java-spring-boot/blob/main/src/test/java/com/behl/cachetropolis/service/WizardServiceTest.java)
* [MasterHouseServiceTest.java](https://github.com/hardikSinghBehl/redis-caching-java-spring-boot/blob/main/src/test/java/com/behl/cachetropolis/service/MasterHouseServiceTest.java)Tests can be executed with the below command
```
mvn test
```---
### Local Setup Instructions
Execute the following commands in the project's base directory to launch the necessary containers:```bash
sudo docker-compose build
```
```bash
sudo docker-compose up -d
```
Docker Compose will start containers for MySQL, Redis, and the Backend Application, all within the same network.Access Swagger UI at `http://localhost:8080/swagger-ui.html`