Caching Articles
Articles covering caching strategies and implementation patterns using Spring Cache, Caffeine, and Redis.
-
How to Implement a Second-Level Cache with @CacheNamespace in Spring Boot + MyBatis - cache Tag and Redis Integration
This article explains how to use MyBatis's built-in second-level cache mechanism to reduce DB load for read-heavy Mappers. It covers the basic behavior of the cache tag and PerpetualCache, defining configuration via Java Config with @CacheNamespace, automatic flushing on INSERT/UPDATE, sharing caches across multiple Mappers with @CacheNamespaceRef, and the steps to swap in a custom Cache implementation backed by Redis, along with configuration examples in Spring Boot.
-
How to Configure and Tune Caffeine Cache in Spring Boot - From expireAfterWrite and maximumSize to Production Operations with stats()
A practical guide to tuning Caffeine cache per-cache in Spring Boot. Covers the distinction between expireAfterWrite and expireAfterAccess, size management with maximumSize and Weigher, asynchronous refresh with refreshAfterWrite, and hit ratio monitoring with recordStats() and Micrometer — everything you need to know before going to production.
-
How to Use Redis with Spring Boot - Implementation Patterns for Session Management, Caching, and Pub/Sub
Learn how to solve common issues such as sessions not being shared across multiple instances and switching the backend of @Cacheable using Redis. This article covers connection configuration for spring-boot-starter-data-redis, session externalization with Spring Session, RedisCacheManager, and Pub/Sub implementation, with code examples for each use case.
-
How to Use Spring Boot Caching - Easy Performance Improvements with @Cacheable
A hands-on guide covering how Spring Cache Abstraction works, how to use @Cacheable, @CacheEvict, and @CachePut, switching to Caffeine and Redis, and measuring hit rates with Micrometer, all with practical code examples. Aimed at beginner-to-intermediate developers who want to fix response latency caused by redundant DB or external API calls with just a few lines of annotations.