package com.ruoyi.common.third.cache.redis;

import com.ruoyi.common.third.cache.AbstractHzCacheManager;
import com.ruoyi.common.third.cache.HzCache;
import org.springframework.cache.Cache;
import org.springframework.data.redis.cache.RedisCache;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisConnectionFactory;

import java.util.Collection;


public class RedisManager extends AbstractHzCacheManager {
    private RedisCacheManager cacheManager;
    private final RedisConnectionFactory redisConnectionFactory;
    private final HzRedisCacheWriter redisCacheWriter;
    public RedisManager(RedisCacheManager cacheManager, RedisConnectionFactory redisConnectionFactory, HzRedisCacheWriter redisCacheWriter) {
        this.cacheManager = cacheManager;
        this.redisConnectionFactory = redisConnectionFactory;
        this.redisCacheWriter = redisCacheWriter;
    }

    @Override
    public HzCache cover(Cache cache) {
        return new HzRedisCache((RedisCache)cache,redisCacheWriter,redisConnectionFactory);
    }

    @Override
    public HzCache getMissingCache(String cacheName) {
        return cover(cacheManager.getCache(cacheName));
    }
    @Override
    public Collection<String> getCacheNames() {
        return cacheManager.getCacheNames();
    }
}
