wxiaoqi / ace-cache Goto Github PK
View Code? Open in Web Editor NEW基于spring boot上的注解缓存,自带轻量级缓存管理页面。@Cache比spring cache更轻量的缓存,支持单个缓存设置过期时间,可以根据前缀移除缓存。采用fastjson序列化与反序列化,以json串存于缓存之中。ace-cache可以快速用于日常的spring boot应用之中。
License: Apache License 2.0
基于spring boot上的注解缓存,自带轻量级缓存管理页面。@Cache比spring cache更轻量的缓存,支持单个缓存设置过期时间,可以根据前缀移除缓存。采用fastjson序列化与反序列化,以json串存于缓存之中。ace-cache可以快速用于日常的spring boot应用之中。
License: Apache License 2.0
跟踪了代码。当缓存的value是string是由于fastjson的转义解析json会出错,造成缓存失效。
按照使用说明在项目里配置redis参数
#redis-cache 相关
redis:
pool:
maxActive: 300
maxIdle: 100
maxWait: 1000
host: 127.0.0.1
port: 6379
password:
timeout: 2000
# 服务或应用名
sysName: ace
enable: true
database: 0
问题:将 database: 0 改为 database: 1,或者 database: 2,均不生效,使用的还是 database: 0?
分析:定位到问题点为 RedisConfig.java 类
@Bean(name = "pool")
public JedisPool constructJedisPool() {
String ip = this.host;
int port = Integer.parseInt(this.port);
String password = this.password;
int timeout = Integer.parseInt(this.timeout);
int database = Integer.parseInt(this.database);
if (null == pool) {
if (StringUtils.isBlank(password)) {
pool = new JedisPool(constructJedisPoolConfig(), ip, port, timeout);
} else {
pool = new JedisPool(constructJedisPoolConfig(), ip, port, timeout, password, database);
}
}
return pool;
}
当password为空时,
pool = new JedisPool(constructJedisPoolConfig(), ip, port, timeout);
此时 database 的参数未使用。
查看 JedisPool 构造函数发现:
public JedisPool(GenericObjectPoolConfig poolConfig, String host, int port, int timeout) {
this(poolConfig, host, port, timeout, (String)null, 0, (String)null);
}
public JedisPool(GenericObjectPoolConfig poolConfig, String host, int port, int timeout, String password, int database, String clientName) {
this(poolConfig, host, port, timeout, timeout, password, database, clientName, false, (SSLSocketFactory)null, (SSLParameters)null, (HostnameVerifier)null);
}
使用的database为0。
解决:建议将
pool = new JedisPool(constructJedisPoolConfig(), ip, port, timeout);
修改为
pool = new JedisPool(constructJedisPoolConfig(), ip, port, timeout, (String)null, database);
调整后的函数为:
@Bean(name = "pool")
public JedisPool constructJedisPool() {
String ip = this.host;
int port = Integer.parseInt(this.port);
String password = this.password;
int timeout = Integer.parseInt(this.timeout);
int database = Integer.parseInt(this.database);
if (null == pool) {
if (StringUtils.isBlank(password)) {
pool = new JedisPool(constructJedisPoolConfig(), ip, port, timeout, (String)null, database);
} else {
pool = new JedisPool(constructJedisPoolConfig(), ip, port, timeout, password, database);
}
}
return pool;
}
这个cache 是否处理 缓存击穿
有解决办法吗?
我项目是logback,不想说再引入一个log4j
这个库挺好的,就是maven搜不到,安装不了,可惜了,希望作者上maven
在并发状态下 可以同时进入
我的项目创建了几个ResponseResultVo,Base包含了一些基本的错误信息,错误码,数据等,新建一个PageResponseResultVo继承了它包含了分页信息,这个时候使用BaseResponseResultVo作为方法返回值生成缓存没问题,但是缓存生效后无法转为PageResponseResultVo,分页信息丢失,原因就是json转换时不能使用方法原来的返回值作为对象转换而是使用了方法标注的返回值转换。希望能改善下这个问题,包括支持范型等问题。
添加redis配置信息(非127.0.0.1)后,启动项目后获取的还是本机的redis服务
返回值类型为String时能缓存但无法读取缓存,现象是Redis有缓存的内容,但是每次还会走进缓存的方法中,返回值类型换成JSONObject后可以读取到了
希望支持web管理端账号密码配置,进入web管理端时,输入账号密码验证
DefaultKeyGenerator类中
if (parameterTypes[index].isAssignableFrom(List.class))
可以优化为
if (!(parameterTypes[index] instanceof Object) && parameterTypes[index].isAssignableFrom(List.class))
1.0版本没上maven吗? 找不到
怎么无法跳到index.html页面呢~ 😓
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.