com.github.rexsheng.springboot.faster.system.cache.CacheConfig Maven / Gradle / Ivy
The newest version!
package com.github.rexsheng.springboot.faster.system.cache;
import com.github.benmanes.caffeine.cache.*;
import com.github.rexsheng.springboot.faster.cache.MultilevelCacheProperties;
import com.github.rexsheng.springboot.faster.system.modular.SpringModule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.caffeine.CaffeineCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisConnectionFactory;
@EnableCaching
@ConditionalOnClass({Caffeine.class, RedisConnectionFactory.class})
@ConditionalOnProperty(prefix = "app.module.cache",name = "enabled",havingValue = "true",matchIfMissing = false)
@SpringModule
public class CacheConfig {
private static final Logger logger= LoggerFactory.getLogger(CacheConfig.class);
@Bean("caffeineRedisCacheManager")
@Primary
public CaffeineRedisCacheManager caffeineRedisCacheManager(MultilevelCacheProperties multilevelCacheProperties,
ObjectProvider caffeineCacheManagers,
ObjectProvider redisCacheManagers) {
return new CaffeineRedisCacheManager(multilevelCacheProperties,caffeineCacheManagers,redisCacheManagers);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy