Giter Site home page Giter Site logo

jetcache's Introduction

JetCache 源码分析

Build Status Coverage Status GitHub release License

当前 master 分支的版本为 2.5.x

该工程已经对 JetCache 的大部分核心内容进行了比较详细的源码注释与分析,对应的源码分析文章可查看我的博客园月圆吖

《JetCache 缓存框架的使用以及源码分析》

简介

JetCache是一个基于Java的缓存系统封装,提供统一的API和注解来简化缓存的使用。 JetCache提供了比SpringCache更加强大的注解,可以原生的支持TTL、两级缓存、分布式自动刷新,还提供了Cache接口用于手工缓存操作。 当前有四个实现:RedisCacheRedisLettuceCacheCaffeineCacheLinkedHashMapCache

特性:

  • 通过统一的API访问Cache系统

  • 通过注解实现声明式的方法缓存,支持TTL和两级缓存

  • 通过注解创建并配置Cache实例

  • 针对所有Cache实例和方法缓存的自动统计

  • Key的生成策略和Value的序列化策略支持自定义配置

  • 分布式缓存自动刷新,分布式锁

  • 异步Cache API (使用Redis的Lettuce客户端时)

缓存类型:

  • 本地

    LinkedHashMap:使用LinkedHashMap做LUR方式淘汰

    Caffeine:基于Java8开发的提供了近乎最佳命中率的高性能的缓存库

  • 远程(访问Redis的客户端)

    Redis:使用Jedis客户端,Redis官方首选的Java客户端

    RedisSpringData:使用SpringData访问Redis(官网未作介绍)

    RedisLettuce:使用Lettuce客户端,一个高性能基于Java的Redis驱动框架,支持线程安全的同步、异步操作,底层集成了Project Reactor,提供反应式编程,参考:Redis高级客户端Lettuce详解

为什么使用缓存?

在高并发、大流量等场景下,降低系统延迟,缓解数据库压力,提高系统整体的性能,让用户有更好的体验。

使用场景

读多写少、不追求强一致性、请求入参不易变化

使用规范

选择了远程缓存请设置keyPrefix,保证存放至Redis的缓存key规范化,避免与其他系统出现冲突,例如这样设计:系统简称:所属名字:,这样存储到Redis的缓存key为:系统简称:所属名字:缓存key

选择了本地缓存请设置limit,全局默认设置了100,本地缓存的数据存放于内存,减轻内存的损耗,如果使用了Caffeine,缓存的key过多可能导致内存溢出

请勿滥用缓存注解,对于非必要添加缓存的方法我们尽量不使用缓存

jetcache's People

Contributors

areyouok avatar blindpirate avatar darknesstm avatar liu844869663 avatar ivan97 avatar amjad1210 avatar charlesvhe avatar chenchi2038 avatar xiaolongyuan avatar scolia avatar

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.