|
@@ -5,21 +5,13 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
|
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
|
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator;
|
|
import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator;
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
-import org.springframework.cache.CacheManager;
|
|
|
|
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
|
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
|
import org.springframework.cache.annotation.EnableCaching;
|
|
import org.springframework.cache.annotation.EnableCaching;
|
|
-import org.springframework.cache.concurrent.ConcurrentMapCache;
|
|
|
|
-import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
|
|
|
|
-import org.springframework.cache.interceptor.KeyGenerator;
|
|
|
|
-import org.springframework.cache.interceptor.SimpleKeyGenerator;
|
|
|
|
-import org.springframework.cache.support.SimpleCacheManager;
|
|
|
|
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.RedisCacheConfiguration;
|
|
import org.springframework.data.redis.cache.RedisCacheManager;
|
|
import org.springframework.data.redis.cache.RedisCacheManager;
|
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
|
-import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
import org.springframework.data.redis.core.script.DefaultRedisScript;
|
|
import org.springframework.data.redis.core.script.DefaultRedisScript;
|
|
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
|
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
|
@@ -28,11 +20,6 @@ import org.springframework.data.redis.serializer.RedisSerializationContext;
|
|
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
|
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
|
|
|
|
|
import java.time.Duration;
|
|
import java.time.Duration;
|
|
-import java.util.Arrays;
|
|
|
|
-
|
|
|
|
-import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
|
|
|
-import org.springframework.data.redis.serializer.RedisSerializationContext;
|
|
|
|
-import org.springframework.data.redis.serializer.StringRedisSerializer;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* redis配置
|
|
* redis配置
|
|
@@ -43,20 +30,19 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
|
|
@EnableCaching
|
|
@EnableCaching
|
|
public class RedisConfig extends CachingConfigurerSupport
|
|
public class RedisConfig extends CachingConfigurerSupport
|
|
{
|
|
{
|
|
-// @Bean
|
|
|
|
-// public CacheManager cacheManager() {
|
|
|
|
-// SimpleCacheManager cacheManager = new SimpleCacheManager();
|
|
|
|
-// cacheManager.setCaches(Arrays.asList(
|
|
|
|
-// new ConcurrentMapCache("getCourseCate"),
|
|
|
|
-// new ConcurrentMapCache("getProductCateByPid"),
|
|
|
|
-// new ConcurrentMapCache("getCourseList"),
|
|
|
|
-// new ConcurrentMapCache("getAppAdvList"),
|
|
|
|
-// new ConcurrentMapCache("getAdvList")
|
|
|
|
-// ));
|
|
|
|
-// return cacheManager;
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
+ @Bean
|
|
|
|
+ public RedisCacheManager cacheManager(RedisConnectionFactory connectionFactory) {
|
|
|
|
+ RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig()
|
|
|
|
+ .entryTtl(Duration.ofSeconds(30))
|
|
|
|
+ .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer()))
|
|
|
|
+ .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer()))
|
|
|
|
+ .disableCachingNullValues();
|
|
|
|
+
|
|
|
|
+ return RedisCacheManager.builder(connectionFactory)
|
|
|
|
+ .cacheDefaults(config)
|
|
|
|
+ .build();
|
|
|
|
+ }
|
|
|
|
|
|
@Bean
|
|
@Bean
|
|
@SuppressWarnings(value = { "unchecked", "rawtypes" })
|
|
@SuppressWarnings(value = { "unchecked", "rawtypes" })
|