【更新】默认使用redis缓存
This commit is contained in:
parent
f4e10f2752
commit
ccdba71ea1
@ -52,7 +52,6 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
<optional>true</optional>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>io.lettuce</groupId>
|
||||
@ -63,7 +62,6 @@
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- jwt token -->
|
||||
|
@ -26,14 +26,16 @@ package vip.xiaonuo.sys.config;
|
||||
|
||||
import cn.hutool.cache.CacheUtil;
|
||||
import cn.hutool.cache.impl.TimedCache;
|
||||
import vip.xiaonuo.core.context.constant.ConstantContextHolder;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
import vip.xiaonuo.core.pojo.login.SysLoginUser;
|
||||
import vip.xiaonuo.sys.core.cache.MappingCache;
|
||||
import vip.xiaonuo.sys.core.cache.ResourceCache;
|
||||
import vip.xiaonuo.sys.core.cache.UserCache;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import vip.xiaonuo.sys.core.redis.FastJson2JsonRedisSerializer;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -57,20 +59,30 @@ public class CacheConfig {
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录用户的缓存,默认过期时间,根据系统sys_config中的常量决定
|
||||
* 登录用户的缓存,redis缓存
|
||||
*
|
||||
* @author yubaoshan
|
||||
* @date 2020/7/9 11:44
|
||||
*/
|
||||
@Bean
|
||||
public UserCache userCache() {
|
||||
TimedCache<String, SysLoginUser> timedCache =
|
||||
CacheUtil.newTimedCache(ConstantContextHolder.getSessionTokenExpireSec() * 1000);
|
||||
public UserCache userCache(RedisTemplate<String, SysLoginUser> redisTemplate) {
|
||||
return new UserCache(redisTemplate);
|
||||
}
|
||||
|
||||
// 定时清理缓存,间隔1秒
|
||||
timedCache.schedulePrune(1000);
|
||||
|
||||
return new UserCache(timedCache);
|
||||
/**
|
||||
* redis缓存类
|
||||
*
|
||||
* @author yubaoshan
|
||||
* @date 2020/4/19 17:53
|
||||
*/
|
||||
@Bean
|
||||
public RedisTemplate<String, SysLoginUser> redisTemplate(RedisConnectionFactory factory) {
|
||||
RedisTemplate<String, SysLoginUser> userRedisTemplate = new RedisTemplate<>();
|
||||
userRedisTemplate.setConnectionFactory(factory);
|
||||
userRedisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
userRedisTemplate.setValueSerializer(new FastJson2JsonRedisSerializer<>(SysLoginUser.class));
|
||||
userRedisTemplate.afterPropertiesSet();
|
||||
return userRedisTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -24,9 +24,9 @@ Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意
|
||||
*/
|
||||
package vip.xiaonuo.sys.core.cache;
|
||||
|
||||
import cn.hutool.cache.impl.TimedCache;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import vip.xiaonuo.core.pojo.login.SysLoginUser;
|
||||
import vip.xiaonuo.sys.core.cache.base.AbstractMemoryCacheOperator;
|
||||
import vip.xiaonuo.sys.core.cache.base.AbstractRedisCacheOperator;
|
||||
|
||||
/**
|
||||
* 登录用户的缓存,存储了当前登录的用户
|
||||
@ -38,19 +38,20 @@ import vip.xiaonuo.sys.core.cache.base.AbstractMemoryCacheOperator;
|
||||
* @author yubaoshan
|
||||
* @date 2020/7/9 11:02
|
||||
*/
|
||||
public class UserCache extends AbstractMemoryCacheOperator<SysLoginUser> {
|
||||
public class UserCache extends AbstractRedisCacheOperator<SysLoginUser> {
|
||||
|
||||
/**
|
||||
* 登录用户缓存前缀
|
||||
*/
|
||||
public static final String LOGIN_USER_CACHE_PREFIX = "LOGIN_USER_";
|
||||
|
||||
public UserCache(TimedCache<String, SysLoginUser> timedCache) {
|
||||
super(timedCache);
|
||||
public UserCache(RedisTemplate<String, SysLoginUser> redisTemplate) {
|
||||
super(redisTemplate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommonKeyPrefix() {
|
||||
return LOGIN_USER_CACHE_PREFIX;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,7 +29,6 @@ import cn.hutool.core.util.StrUtil;
|
||||
import vip.xiaonuo.core.cache.CacheOperator;
|
||||
import vip.xiaonuo.core.consts.SymbolConstant;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -30,7 +30,6 @@ import com.alibaba.fastjson.parser.ParserConfig;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.data.redis.serializer.SerializationException;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
|
@ -27,7 +27,6 @@ package vip.xiaonuo.sys.modular.auth.service;
|
||||
import vip.xiaonuo.core.pojo.login.SysLoginUser;
|
||||
import vip.xiaonuo.sys.modular.user.entity.SysUser;
|
||||
import org.springframework.security.core.Authentication;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
|
@ -5,6 +5,10 @@ spring:
|
||||
url: jdbc:mysql://localhost:3306/snowy-pub?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=CTT&nullCatalogMeansCurrent=true
|
||||
username: root
|
||||
password: 123456
|
||||
redis:
|
||||
host: localhost
|
||||
port: 6379
|
||||
password:
|
||||
|
||||
# Oracle数据库
|
||||
#spring:
|
||||
|
@ -5,6 +5,10 @@ spring:
|
||||
url: jdbc:mysql://localhost:3306/snowy-pub?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=CTT&nullCatalogMeansCurrent=true
|
||||
username: root
|
||||
password: 123456
|
||||
redis:
|
||||
host: localhost
|
||||
port: 6379
|
||||
password:
|
||||
|
||||
# Oracle数据库
|
||||
#spring:
|
||||
|
@ -5,6 +5,10 @@ spring:
|
||||
url: jdbc:mysql://localhost:3306/snowy-pub?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=CTT&nullCatalogMeansCurrent=true
|
||||
username: root
|
||||
password: 123456
|
||||
redis:
|
||||
host: localhost
|
||||
port: 6379
|
||||
password:
|
||||
|
||||
# Oracle数据库
|
||||
#spring:
|
||||
|
Loading…
x
Reference in New Issue
Block a user