CacheConfig.java 964 Bytes
package com.tanpu.community.config;

import com.tanpu.community.cache.RedisCache;
import com.tanpu.community.util.SpringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.caffeine.CaffeineCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;

@Configuration
public class CacheConfig {

    @Autowired
    private SpringUtils springUtils;

    @Bean
    public RedisCache redisCache() {
        return new RedisCache.Builder().cacheName("community2").build();
    }

    @Bean
    public CaffeineCacheManager caffeineCacheManager() {
        CaffeineCacheManager cacheManager = new CaffeineCacheManager();
        cacheManager.setCacheNames(Arrays.asList("local"));
        // todo 配置化
        cacheManager.setCacheSpecification("maximumSize=1000,expireAfterWrite=30s");
        return cacheManager;
    }
}