I think @mavarazy's answer is the best. I add only if you need automatic configuration of the missing cache, you can do it as follows.
First, define your own cache manager, which creates an automatic cache if you need it:
public class MyCacheManager extends SimpleCacheManager { @Override protected Cache getMissingCache(String name) {
And now you can define the cache manager configuration:
@Bean public CacheManager cacheManager() { SimpleCacheManager simpleCacheManager = new MyCacheManager(); GuavaCache specificCacheConfig = new GuavaCache("specificCacheConfigName", CacheBuilder.newBuilder().expireAfterAccess(60, TimeUnit.MINUTES).build()); simpleCacheManager.setCaches(Collections.singletonList(specificCacheConfig)); return simpleCacheManager; }
Przemek nowak
source share