|
@@ -1,17 +1,14 @@
|
|
|
package cn.reghao.dfs.store.config;
|
|
package cn.reghao.dfs.store.config;
|
|
|
|
|
|
|
|
|
|
+import com.github.benmanes.caffeine.cache.Caffeine;
|
|
|
import org.springframework.cache.CacheManager;
|
|
import org.springframework.cache.CacheManager;
|
|
|
import org.springframework.cache.annotation.EnableCaching;
|
|
import org.springframework.cache.annotation.EnableCaching;
|
|
|
|
|
|
|
|
|
|
+import org.springframework.cache.caffeine.CaffeineCacheManager;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
-import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
|
|
|
|
-import org.springframework.data.redis.cache.RedisCacheManager;
|
|
|
|
|
-import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
|
-import org.springframework.data.redis.serializer.RedisSerializationContext;
|
|
|
|
|
|
|
|
|
|
-import java.time.Duration;
|
|
|
|
|
-import java.util.Objects;
|
|
|
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 缓存配置
|
|
* 缓存配置
|
|
@@ -22,7 +19,7 @@ import java.util.Objects;
|
|
|
@EnableCaching
|
|
@EnableCaching
|
|
|
@Configuration
|
|
@Configuration
|
|
|
public class CacheConfig {
|
|
public class CacheConfig {
|
|
|
- @Bean
|
|
|
|
|
|
|
+ /*@Bean
|
|
|
public CacheManager cacheManager(RedisTemplate<String, Object> template) {
|
|
public CacheManager cacheManager(RedisTemplate<String, Object> template) {
|
|
|
RedisCacheConfiguration config = RedisCacheConfiguration
|
|
RedisCacheConfiguration config = RedisCacheConfiguration
|
|
|
.defaultCacheConfig()
|
|
.defaultCacheConfig()
|
|
@@ -36,5 +33,21 @@ public class CacheConfig {
|
|
|
.cacheDefaults(config)
|
|
.cacheDefaults(config)
|
|
|
.transactionAware()
|
|
.transactionAware()
|
|
|
.build();
|
|
.build();
|
|
|
|
|
+ }*/
|
|
|
|
|
+
|
|
|
|
|
+ @Bean
|
|
|
|
|
+ public CacheManager cacheManager() {
|
|
|
|
|
+ CaffeineCacheManager cacheManager = new CaffeineCacheManager();
|
|
|
|
|
+ Caffeine<Object, Object> caffeineCache = caffeineCache();
|
|
|
|
|
+ cacheManager.setCaffeine(caffeineCache);
|
|
|
|
|
+ return cacheManager;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Bean("caffeineCache")
|
|
|
|
|
+ public Caffeine<Object, Object> caffeineCache() {
|
|
|
|
|
+ return Caffeine.newBuilder()
|
|
|
|
|
+ .initialCapacity(1000)
|
|
|
|
|
+ .maximumSize(10_000)
|
|
|
|
|
+ .expireAfterAccess(365, TimeUnit.DAYS);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|