parent
1dc81a8051
commit
37bd21ccfc
8 changed files with 106 additions and 71 deletions
@ -0,0 +1,48 @@ |
|||||||
|
package com.huoran.iasf.common.config; |
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.cache.CacheProperties; |
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties; |
||||||
|
import org.springframework.cache.annotation.EnableCaching; |
||||||
|
import org.springframework.context.annotation.Bean; |
||||||
|
import org.springframework.context.annotation.Configuration; |
||||||
|
import org.springframework.data.redis.cache.RedisCacheConfiguration; |
||||||
|
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; |
||||||
|
import org.springframework.data.redis.serializer.RedisSerializationContext; |
||||||
|
import org.springframework.data.redis.serializer.StringRedisSerializer; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author chen |
||||||
|
* @DATE 2021/12/28 10:42 |
||||||
|
* @Version 1.0 |
||||||
|
*/ |
||||||
|
@EnableConfigurationProperties(CacheProperties.class) |
||||||
|
@Configuration |
||||||
|
@EnableCaching |
||||||
|
public class MyCacheConfig { |
||||||
|
|
||||||
|
@Bean |
||||||
|
RedisCacheConfiguration redisCacheConfiguration(CacheProperties cacheProperties){ |
||||||
|
RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig(); |
||||||
|
//修改缓存key、value的序列化机制,返回json数据格式
|
||||||
|
config.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer())); |
||||||
|
config.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer())); |
||||||
|
//读取redis配置文件
|
||||||
|
CacheProperties.Redis redisProperties = cacheProperties.getRedis(); |
||||||
|
if (redisProperties.getTimeToLive() != null) { |
||||||
|
config = config.entryTtl(redisProperties.getTimeToLive()); |
||||||
|
} |
||||||
|
|
||||||
|
if (redisProperties.getKeyPrefix() != null) { |
||||||
|
config = config.prefixKeysWith(redisProperties.getKeyPrefix()); |
||||||
|
} |
||||||
|
|
||||||
|
if (!redisProperties.isCacheNullValues()) { |
||||||
|
config = config.disableCachingNullValues(); |
||||||
|
} |
||||||
|
|
||||||
|
if (!redisProperties.isUseKeyPrefix()) { |
||||||
|
config = config.disableKeyPrefix(); |
||||||
|
} |
||||||
|
return config; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,29 @@ |
|||||||
|
package com.huoran.iasf.common.config; |
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean; |
||||||
|
import org.springframework.context.annotation.Configuration; |
||||||
|
|
||||||
|
import java.util.concurrent.Executors; |
||||||
|
import java.util.concurrent.LinkedBlockingDeque; |
||||||
|
import java.util.concurrent.ThreadPoolExecutor; |
||||||
|
import java.util.concurrent.TimeUnit; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author chen |
||||||
|
* @DATE 2021/12/28 17:48 |
||||||
|
* @Version 1.0 |
||||||
|
*/ |
||||||
|
@Configuration |
||||||
|
public class MyThreadConfig { |
||||||
|
|
||||||
|
@Bean |
||||||
|
public ThreadPoolExecutor threadPoolExecutor(){ |
||||||
|
return new ThreadPoolExecutor(20, |
||||||
|
300, |
||||||
|
10, |
||||||
|
TimeUnit.SECONDS, |
||||||
|
new LinkedBlockingDeque<>(), |
||||||
|
Executors.defaultThreadFactory(), |
||||||
|
new ThreadPoolExecutor.AbortPolicy()); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue