Skip to content

AlaaAlasrawi/redis-cache-learning

Repository files navigation

redis-cache-learning

A beginner-friendly Spring Boot project that demonstrates Redis caching using Spring Cache (@Cacheable) with a TTL (time-to-live). The first request is slow (simulated external API call), and the next requests are fast because the response is served from Redis until the TTL expires.

Tech Used

  • Java 21
  • Spring Boot
  • Spring Cache (@EnableCaching, @Cacheable)
  • Spring Data Redis (Redis as cache store)
  • Docker Compose (Redis container)
  • Gradle

How It Works

  • The API endpoint calls a service method annotated with @Cacheable.
  • On the first request (cache miss), the method runs and stores the result in Redis.
  • On the next request (cache hit), Spring returns the cached value from Redis.
  • After the TTL expires, the cache entry is removed and the next request refreshes it.

Run Redis

From the project root:

docker compose up -d

About

Spring Boot weather API with Redis caching (Spring Cache) and configurable TTL to reduce external calls.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages