Skip to content

Spring Boot backend demonstrating Redis cache-aside with MySQL, manual RedisTemplate caching, TTL, and proper cache invalidation.

Notifications You must be signed in to change notification settings

AkashKobal/cache-management

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.”

About

Spring Boot backend demonstrating Redis cache-aside with MySQL, manual RedisTemplate caching, TTL, and proper cache invalidation.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages