Giter Site home page Giter Site logo

wxiaoqi / ace-cache Goto Github PK

View Code? Open in Web Editor NEW
176.0 176.0 107.0 191 KB

基于spring boot上的注解缓存,自带轻量级缓存管理页面。@Cache比spring cache更轻量的缓存,支持单个缓存设置过期时间,可以根据前缀移除缓存。采用fastjson序列化与反序列化,以json串存于缓存之中。ace-cache可以快速用于日常的spring boot应用之中。

License: Apache License 2.0

Java 100.00%

ace-cache's Introduction

Hi 👋

谢谢你关注我,推荐关注我的公众号:cloud-platform 👋👋👋

wxiaoqi's github stats

输入图片说明

ace-cache's People

Contributors

billho avatar wxiaoqi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ace-cache's Issues

database设置没有生效的问题

按照使用说明在项目里配置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;
}

目前发现一个问题,关于返回值是Object或父类问题

我的项目创建了几个ResponseResultVo,Base包含了一些基本的错误信息,错误码,数据等,新建一个PageResponseResultVo继承了它包含了分页信息,这个时候使用BaseResponseResultVo作为方法返回值生成缓存没问题,但是缓存生效后无法转为PageResponseResultVo,分页信息丢失,原因就是json转换时不能使用方法原来的返回值作为对象转换而是使用了方法标注的返回值转换。希望能改善下这个问题,包括支持范型等问题。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.