package vip.xiaonuo.coldchain.core.cache.monitordevice.factory;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import vip.xiaonuo.coldchain.core.cache.monitordevice.MonitorDeviceCacheService;
import vip.xiaonuo.coldchain.core.cache.monitordevice.impl.LocalMonitorDeviceCacheService;
import vip.xiaonuo.coldchain.core.cache.monitordevice.impl.RedisMonitorDeviceCacheService;
import vip.xiaonuo.coldchain.core.renke.config.JfcloudColdChainServerProperties;

import static vip.xiaonuo.coldchain.core.config.JfcloudColdChainConstants.DEFAULT_CACHE_TYPE;
/**
 * @author jackzhou
 * @version 1.0
 * @project jfcloud-coldchain
 * @description
 * @date 2024/11/19 17:37:02
 */


/**
 * 缓存选择器，根据配置决定使用 Redis 缓存还是本地缓存
 */
@Configuration
public class MonitorDeviceCacheServiceFactory {

    @Bean
    public MonitorDeviceCacheService cacheService(JfcloudColdChainServerProperties jfcloudColdChainServerProperties, RedisMonitorDeviceCacheService redisCacheService, LocalMonitorDeviceCacheService localCacheService) {
        if (DEFAULT_CACHE_TYPE.equalsIgnoreCase(jfcloudColdChainServerProperties.getCacheType())) {
            return redisCacheService;  // 使用 Redis 缓存
        } else {
            return localCacheService;  // 使用本地缓存
        }
    }
}
