BAEL-3730: Add example of usage CacheManagerCustomizer in Spring Boot (#9048)

This commit is contained in:
kwoyke
2020-04-10 21:58:48 +02:00
committed by GitHub
parent 0789662084
commit 82e69447a5
4 changed files with 66 additions and 0 deletions
@@ -0,0 +1,14 @@
package com.baeldung.caching.boot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
@SpringBootApplication
@EnableCaching
public class CacheApplication {
public static void main(String[] args) {
SpringApplication.run(CacheApplication.class, args);
}
}
@@ -0,0 +1,24 @@
package com.baeldung.caching.boot;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.cache.CacheManagerCustomizer;
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
import org.springframework.stereotype.Component;
import static java.util.Arrays.asList;
@Component
public class SimpleCacheCustomizer implements CacheManagerCustomizer<ConcurrentMapCacheManager> {
private static final Logger LOGGER = LoggerFactory.getLogger(SimpleCacheCustomizer.class);
static final String USERS_CACHE = "users";
static final String TRANSACTIONS_CACHE = "transactions";
@Override
public void customize(ConcurrentMapCacheManager cacheManager) {
LOGGER.info("Customizing Cache Manager");
cacheManager.setCacheNames(asList(USERS_CACHE, TRANSACTIONS_CACHE));
}
}