Skip to content

Latest commit

 

History

History
126 lines (92 loc) · 1.97 KB

File metadata and controls

126 lines (92 loc) · 1.97 KB

Cache Management System

Spring Boot + MySQL + Redis

A backend project demonstrating Redis caching in Spring Boot using the
Cache-Aside Pattern, where MySQL is the source of truth and Redis is used for fast reads.

This project avoids Spring’s cache abstraction to explicitly show how caching works internally.


🧠 System Design (High Level)

📌 System architecture and flow diagram

dependencies.png dependencies.png


🚀 Tech Stack

  • Spring Boot
  • Spring Data JPA
  • MySQL
  • Redis
  • RedisTemplate (Manual Caching)
  • Maven

📦 Dependencies Used

Key dependencies:

  • spring-boot-starter-web
  • spring-boot-starter-data-jpa
  • spring-boot-starter-data-redis
  • mysql-connector-j
  • jackson-databind
  • jackson-datatype-jsr310
  • lombok

⚙️ Prerequisites

  • Java 17+
  • Maven
  • MySQL
  • Redis (Windows build)

🛢️ MySQL Setup

Create database:

CREATE DATABASE cache_db;

Redis Installation (Windows)

Download Redis

🔗 https://github.com/tporadowski/redis/releases

Verify Redis Installation

redis-server --version

Start Redis

redis-server

Verify Redis is Running

redis-cli ping

Expected output:

PONG

Open Redis CLI

redis-cli

Run the Spring Boot Application

Verify Redis Cache (redis-cli)

List All Keys

KEYS *

Expected:

product:list
product:{id}

Read Cached Product List

GET product:list 

Check TTL

TTL product:list

Caching Strategy Explained

GET → Redis first, DB on cache miss

POST / UPDATE / DELETE

Write to DB first Invalidate Redis cache TTL used as safety net No @Cacheable, no CacheManager Interview-Ready Summary “This project implements a cache-aside pattern using RedisTemplate, where Redis is checked first for reads, MySQL is the source of truth, and cache is invalidated after successful write operations.”