common-cache 使用说明
chenweida editou esta página 6 anos atrás

1、依赖common-cache工程

    <dependency>
        <groupId>com.yihu.base</groupId>
        <artifactId>common-cache </artifactId>
        <version>${版本以项目中最新的版本为主}</version>
    </dependency>

2、在yml中添加配置

    cache: # 1-内存 2-redis
      type: 1
      expire-time: 2 #单位为小时
      refresh-time: 1.5

    spring:
      redis:
        host: 172.19.103.88 # ip
        port: 6379 # R端口
        database: 0 # 默认使用DB0
        timeout: 0 # 连接超时时间(毫秒)

3、使用Spring Cache注解方式使用缓存,spring cache了解参考

    http://blog.csdn.net/sanjay_f/article/details/47372967

4、项目中引用

    因为spring cache没有提供缓存失效的实现,所以在原有的spring cache改进,使用注解配置的时候添加上我们需要的缓存过期时间和自动刷新时间即可,如下:
    @Cacheable(value = "cacheName#2#1") 以“#”为分隔符,2为缓存过期时间,1为自动刷新时间