Usage
This guide shows you how to integrate Redis Cache Java into your Java application.
Basic Setup
To use Redis Cache Java as a backing implementation, add RedisCacheManager to your configuration:
@Bean
public RedisCacheManager cacheManager(RedisClient client) {
return RedisCacheManager.create(client);
}
Then you can tag the methods in your application that you want to apply caching to.
Advanced Configuration
RedisCacheManager behavior can be configured with RedisCacheManagerBuilder, letting you set the default RedisCacheConfiguration and predefined caches.
RedisCacheManager cacheManager = RedisCacheManager.builder(client)
.defaults(RedisCacheConfiguration.defaultConfig())
.configuration("hashCache", RedisCacheConfiguration.defaultConfig().hash())
.configuration("jsonCache", RedisCacheConfiguration.defaultConfig().json())
.configuration("stringCache", RedisCacheConfiguration.defaultConfig().string())
.build();
As shown in the preceding example, RedisCacheManager allows custom configuration on a per-cache basis.
The behavior of RedisCache created by RedisCacheManager is defined with RedisCacheConfiguration.
Next Steps
-
Configuration - Learn about all configuration options
-
Features - Explore advanced features
-
Metrics - Set up monitoring