在Spring Boot中配置CacheManager有兩種方法:
import org.springframework.cache.CacheManager;
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.cache.annotation.EnableCaching;
@Configuration
@EnableCaching
public class CacheConfig {
@Bean
public CacheManager cacheManager() {
return new ConcurrentMapCacheManager("cacheName");
}
}
spring.cache.type=caffeine
spring.cache.cache-names=cacheName
spring.cache.caffeine.spec=maximumSize=500,expireAfterAccess=5m
以上是兩種常用的配置CacheManager的方法,可以根據(jù)具體需求選擇適合的方式進行配置。