package com.ssyf.plugs.cache.config;

import com.ssyf.plugs.cache.properties.CacheProperties;
import com.ssyf.plugs.cache.AdaptCacheManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.context.annotation.*;
import org.springframework.data.redis.core.RedisTemplate;



/**
 * springboot 注解使用缓存配置类
 * <p>控制springboot注解缓存底层数据缓存方式</p>
 * @author huwei
 * @date 2023/9/21 15:54
 */
@Configuration
@ConditionalOnBean(CacheProperties.class)
public class CacheConfig {

    @Autowired(required = false)
    private EhCacheCacheManager ehCacheCacheManager;

    @Autowired(required = false)
    private RedisTemplate<String, Object> redisTemplate;

    @Autowired(required = false)
    private CacheProperties cacheProperties;

    @Bean
    @Primary
    public AdaptCacheManager cacheManager() {
        return new AdaptCacheManager(this.ehCacheCacheManager ,this.redisTemplate ,this.cacheProperties);
    }
}
