RedisCacheManager is the Spring Data Redis implementation of Spring's CacheManager interface. It creates and manages named caches whose entries live in Redis, so @Cacheable, @CachePut and @CacheEvict store results in a shared, networked cache instead of in each JVM's memory. Because the data sits in Redis, every application instance sees the same cache, entries can expire with a time-to-live (TTL), and cached data survives an application restart.
In Spring Boot you rarely create it by hand: with spring-boot-starter-data-redis and spring-boot-starter-cache on the classpath, Boot auto-configures a RedisCacheManager for you. You build one yourself when you need per-cache TTLs, a different serializer or transaction support.
Spring's caching abstraction separates the annotations you write from the store that holds the data. A CacheManager hands out Cache objects by name, and each annotation such as @Cacheable("products") asks the manager for the cache called products.
RedisCacheManager (package org.springframework.data.redis.cache) is the Redis-backed manager. For every cache name it creates a RedisCache that:
products::42), so caches do not collide in the same Redis database.RedisCacheConfiguration.RedisCacheWriter, which is built from a RedisConnectionFactory (Lettuce by default in Spring Boot, or Jedis).For most applications, properties are enough. Add the dependencies and enable caching:
The spring.cache.redis.* properties apply to every cache that Boot creates. If you need different settings per cache, define a customizer or your own manager, as shown below.
When you need explicit control, declare a CacheManager bean. Note that RedisCacheConfiguration and RedisCacheManager both live in org.springframework.data.redis.cache, not in org.springframework.cache.
What this configuration does:
entryTtl expires entries automatically, so stale data cannot live forever.disableCachingNullValues makes @Cacheable methods that return null skip the cache. Use it only if null results should not be remembered.Serializable.withInitialCacheConfigurations gives the products and sessions caches their own TTLs. Any other cache name falls back to the defaults.enableStatistics records hits and misses, which you can expose through Micrometer.If you stay with Boot's auto-configured manager and only want per-cache tweaks, register a RedisCacheManagerBuilderCustomizer bean instead of replacing the whole manager.
Once the manager exists, the annotations work as usual:
The first call to findById(42) runs the method and stores the result under products::42. Later calls return the cached value without touching the database until the entry expires or is evicted. Because the abstraction works through a proxy, calling findById from another method of the same class bypasses the cache.
| Concern | Recommendation |
|---|---|
| Serialization | Use JSON or another explicit format. JDK serialization breaks when a class changes and cannot be read by other languages. |
| TTL | Always set one. A cache without expiry becomes a second source of truth. |
| Key prefix | Keep the default prefix on, or set one per application when several apps share one Redis. |
| Cache stampede | Use @Cacheable(sync = true) so only one thread rebuilds a missing entry. |
| Transactions | Call transactionAware() on the builder so cache writes follow Spring transactions. |
| Locking | RedisCacheWriter.lockingRedisCacheWriter makes clear() and some bulk operations safer, at a cost in latency. |
Also remember that Redis is a remote call. Caching cheap operations can make code slower, and a Redis outage should degrade to database reads rather than fail requests. A custom CacheErrorHandler lets you log cache failures and continue.
No. RedisTemplate is a general-purpose client for reading and writing Redis data structures. RedisCacheManager sits on top of the Redis connection and exposes Redis as a Spring Cache, with TTLs and key naming handled for you.
Pass a Map<String, RedisCacheConfiguration> to withInitialCacheConfigurations, or add a RedisCacheManagerBuilderCustomizer bean in a Boot application. Caches not listed use cacheDefaults.
The serializer cannot rebuild the stored object, usually because a class changed or a different serializer wrote the entry. Clear the affected cache after changing the model or serializer, and prefer JSON with stable field names.
Yes. Call cacheManager.getCache("products").clear() or use @CacheEvict(allEntries = true). Both delete the keys with that cache's prefix.
RedisCacheManager connects Spring's caching annotations to Redis, giving you a shared cache with TTLs, key prefixes and pluggable serialization. In Spring Boot, start with the spring.cache.* properties and add a RedisCacheManagerBuilderCustomizer or your own bean when you need per-cache settings. Use JSON serialization, set a TTL on every cache, and treat Redis as a cache that may be unavailable.