Commit 3ca37f01 authored by huangcb's avatar huangcb

缓存前缀设置为applicationName

parent 697a2e5a
......@@ -11,30 +11,30 @@ public class CacheNames {
* author chenfm
* createTime 2020/4/10 14:16
**/
public static final String API_AUTHORITY = "freight-cc::apiAuthority";
public static final String API_AUTHORITY = "apiAuthority";
/**
* description 用户信息
* author chenfm
* createTime 2020/4/10 14:16
**/
public static final String USER_INFO = "freight-cc::userInfo";
public static final String USER_INFO = "userInfo";
/**
* description 系统code对应系统信息
* author chenfm
* createTime 2020/4/10 14:16
**/
public static final String SYSTEM_BY_CODE = "freight-cc::systemByCode";
public static final String SYSTEM_BY_CODE = "systemByCode";
/**
* description 各系统用户权限
* author chenfm
* createTime 2020/4/10 14:16
**/
public static final String SYSTEM_USER_PERM = "freight-cc::systemUserPerm";
public static final String SYSTEM_USER_PERM = "systemUserPerm";
/**
* description 菜单信息
* author chenfm
* createTime 2020/4/10 14:16
**/
public static final String MENU_INFO = "freight-cc::menuInfo";
public static final String MENU_INFO = "menuInfo";
}
......@@ -7,9 +7,11 @@ import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.CacheKeyPrefix;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.cache.RedisCacheWriter;
......@@ -30,6 +32,9 @@ import java.util.Map;
@EnableCaching
public class CacheConfig {
@Value("${spring.application.name}")
private String applicationName;
@Autowired
CacheNameConfig cacheNameConfig;
......@@ -87,13 +92,30 @@ public class CacheConfig {
private RedisCacheConfiguration getRedisCacheConfigurationWithTtl(Integer seconds) {
RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig();
redisCacheConfiguration = redisCacheConfiguration.serializeValuesWith(
RedisSerializationContext.SerializationPair.fromSerializer(jsonSerializer())
).entryTtl(Duration.ofSeconds(seconds));
redisCacheConfiguration = redisCacheConfiguration
.computePrefixWith(cacheKeyPrefix())
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(jsonSerializer()))
.entryTtl(Duration.ofSeconds(seconds));
return redisCacheConfiguration;
}
/**
* @description 设置缓存key的前缀
* @return org.springframework.data.redis.cache.CacheKeyPrefix
* @author huangChaobin@esvtek.com
* @createTime 2020/07/30 19:49
**/
@Bean
public CacheKeyPrefix cacheKeyPrefix() {
return cacheName -> {
StringBuilder sBuilder = new StringBuilder(8);
sBuilder.append(applicationName).append("::");
sBuilder.append(cacheName).append("::");
return sBuilder.toString();
};
}
/**
* RedisTemplate默认使用的序列化机制是JdkSerializationRedisSerializer,这里我们是用Jackson2JsonRedisSerializer
* @return
......
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
druid:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.0.17:3306/iot?useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8
username: iot
password: 123456
initial-size: 5
min-idle: 5
max-active: 20
max-wait: 60000
time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 300000
validation-query: SELECT 1
test-while-idle: true
test-on-borrow: false
test-on-return: false
filter:
stat:
log-slow-sql: true
slow-sql-millis: 1000
merge-sql: false
redis:
host: 192.168.0.17
port: 6379
password:
database: 3
# 连接超时时间(毫秒)默认是2000ms
timeout: 5000
jedis:
pool:
# 连接池最大连接数(使用负值表示没有限制)
max-active: 8
# 连接池最大阻塞等待时间(使用负值表示没有限制)
max-wait: -1
# 连接池中的最大空闲连接
max-idle: 8
# 连接池中的最小空闲连接
min-idle: 0
# 集群配置
# cluster:
# 集群地址(使用','分割)
# nodes:
# 一般当此值设置过大时,容易报:Too many Cluster redirections
# max-redirects: 3
cache:
redis:
## Entry expiration in milliseconds. By default the entries never expire.
# time-to-live: 1d
time-to-live: 2000
#写入redis时是否使用键前缀。
use-key-prefix: true
key-prefix: spring-cache_
#mybatis
mybatis-plus:
mapper-locations: classpath*:/mapper/**/*Dao.xml
#实体扫描,多个package用逗号或者分号分隔
typeAliasesPackage: com.esv.datacenter.cc.entity;com.esv.datacenter.cc.dto;com.esv.datacenter.cc.module.*.entity;com.esv.datacenter.cc.module.*.dto
check-config-location: true
#原生配置
configuration:
map-underscore-to-camel-case: true
cache-enabled: false
call-setters-on-nulls: true
jdbc-type-for-null: 'null'
global-config:
banner: true
#数据库相关配置
db-config:
#主键类型 AUTO:"数据库ID自增", INPUT:"用户输入ID", ID_WORKER:"全局唯一ID (数字类型唯一ID)", UUID:"全局唯一ID UUID";
id-type: AUTO
logic-delete-value: 1
logic-not-delete-value: 0
management:
endpoints:
web:
exposure:
# "*"开放所有监控端点,指定监控端点,用逗号分隔
include: health
base-path: /esvActuator
endpoint:
health:
show-details: always
feign:
hystrix:
enabled: true
hystrix:
command:
default:
execution:
timeout:
enabled: true
isolation:
thread:
timeoutInMilliseconds: 5000
ribbon:
eager-load:
enabled: true
clients: datacenter-base-service
jwt:
generate:
key: upms_hello_world_001
secret:
key: upms_hello_world_101
auth:
noCheck:
URL: /account/loginByAccountPwd,/account/checkToken
#api权限校验开关:true-校验、false-不校验
api:
check:
switch: true
#web端token存活时间,单位小时
token:
live:
time:
web: 12
app:
prop:
super-admin-role-id: 1
cache:
names:
- key: datacenter-cc::apiAuthority
timeout: 600
- key: datacenter-cc::userInfo
timeout: 2592000 # 30天
- key: datacenter-cc::systemByCode
timeout: 2592000
\ No newline at end of file
......@@ -12,7 +12,7 @@ spring:
max-wait: 60000
time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 300000
validation-query: SELECT 1 FROM DUAL
validation-query: SELECT 1
test-while-idle: true
test-on-borrow: false
test-on-return: false
......
......@@ -12,7 +12,7 @@ spring:
max-wait: 60000
time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 300000
validation-query: SELECT 1 FROM DUAL
validation-query: SELECT 1
test-while-idle: true
test-on-borrow: false
test-on-return: false
......
......@@ -12,7 +12,7 @@ spring:
max-wait: 60000
time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 300000
validation-query: SELECT 1 FROM DUAL
validation-query: SELECT 1
test-while-idle: true
test-on-borrow: false
test-on-return: false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment