haozi2015 / autoCache

#autoCache二级缓存# 基于springboot实现的二级缓存组件

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

autoCache

概述

autoCache是一个Java轻量级的二级缓存组件。首先,autoCache 本身并无缓存功能,而是利用内存缓存caffeine和高性能数据库Redis,实现的二级缓存组件。 autoCache 解决高并发场景时缓存逻辑复杂的问题,以极简的方式实现缓存功能,提升系统性能、开发效率。

基本要求

  1. JDK 1.8+
  2. Spring boot 2.0+
  3. 添加依赖
<dependency>
  <groupId>io.github.haozi2015</groupId>
  <artifactId>autocache-spring-boot-starter</artifactId>
  <version>1.0.4</version>
</dependency>

使用说明

方法使用@AutoCache注解,即完成方法的参数和结果缓存。

    // 仅用本地缓存,5秒后过期
    @AutoCache(localTTL = 5)
    String getLocalStr() {
        return "abc";
    }

    // 仅用远程缓存
    @AutoCache(remoteTTL = 30)
    String getRemoteStr() {
        return "abc";
    }
            
    // 二级缓存
    // 优先本地缓存,不存在时查远程缓存,不存在是调用原方法,结果再依次被远程和本地缓存
    // 分别本地缓存5秒过期,远程缓存30秒过期
    @AutoCache(localTTL = 5, remoteTTL = 30)
    String getStr() {
        return "abc";
    }

远程缓存,配置Redis同SpringBoot方式。

更多功能

完整代码,参考demo

TODO

  1. 主动缓存功能
  2. 监控,访问量、命中率、miss率等
  3. 内存缓存的一致性问题

About

#autoCache二级缓存# 基于springboot实现的二级缓存组件

License:Apache License 2.0