Have two classes, both annotating with @Cacheable (org.springframework.cache.annotation.Cacheable), either methods or class. I think it doesn't matter for this question.
Example:
@Cacheable(value = STATE_CACHE_NAME, key = "#root.methodName + '-' + #country?.id ?: \"null\" + '-' + #stateName ?: \"null\"")
public Long getStateId(CountryEntity country, String stateName) {...}
In some classes I'd like to use the simple in-memory cache and others the Redis cache. Both are configured in Spring boot auto-configure CacheConfigurations. How do I state this intent and use the different configurations?
@Cacheabletakes a parameter "cacheManager", which lets you specify which bean ofCacheManagerit refers to.So you'd add it with the name of the bean of your wanted
CacheManager.You can either use the name of the bean method, or provide the name via the "name" parameter of
@Bean.E.g.