当前位置:网站首页>[jetcache] how to use jetcache
[jetcache] how to use jetcache
2022-07-01 22:37:00 【No8g siege lion】
Contents of this article
Two 、JetCache Features and requirements
2.2 JetCache The requirements of
3.2 application.yml To configure
3.4 Add a comment to the method
One 、 Background description
Today, let's talk about Alibaba An open source caching framework JetCache. Its alleged ratio Spring Cache It's easier to use , After I used it, I found it really easy to use , The steps are also very simple .
JetCache It's based on Java The cache system package , Provide uniform API And annotations to simplify the use of cache . JetCache Provides a ratio SpringCache More powerful annotations , Can be native support TTL、 Two level cache 、 Distributed auto refresh , It also provides Cache
Interface for manual caching operations . There are currently four implementations ,RedisCache
、TairCache
( This part is not in github Open source )、CaffeineCache
(in memory) And a simple LinkedHashMapCache
(in memory), It's also very easy to add new implementations .
Two 、JetCache Features and requirements
2.1 JetCache Characteristics
The following is a brief description JetCache Characteristics , It is convenient to do some simple understanding before using :
- Through consistent Cache API Operating the cache .
- Use annotations on methods , Can be realized TTL And two levels of caching .
- Use annotations to create and configure Cache example .
- Automatic collection Cache Access statistics of instance and method cache .
- key Generate and value The serialization strategy can be customized .
- Distributed cache automatic refresh and distributed locking .(2.2)
- Use Cache API Asynchronous access .(2.2 Above version ,redis client )
- Support Spring Boot.
2.2 JetCache The requirements of
- JetCache need JDK1.8、Spring Framework4.0.8 Above version .
- Spring Boot Optional , need 1.1.9 Above version .
- If you don't use annotations ( Use only jetcache-core),Spring Framework Also optional , In this case, it is used in the same way as Guava/Caffeine cache similar .
3、 ... and 、 Use steps
Use steps to spring boot Project as an example :
3.1 Introduce dependencies
Now the latest version is 2.7.0.M1, It will continue to update in the future , If you want to use the latest version, you can go maven Download from the central warehouse of
<!-- jet cache-->
<dependency>
<groupId>com.alicp.jetcache</groupId>
<artifactId>jetcache-starter-redis</artifactId>
<version>2.7.0.M1</version>
</dependency>
3.2 application.yml To configure
First, let's take a picture to record the configuration , Of course, you can also paste directly from the configuration below , ha-ha
If you want to copy and paste directly , From the text box below cv once ( Remember to revise redis Address, user name and password of ) that will do .
jetcache:
statIntervalMinutes: 15
areaInCacheName: false
local:
default:
type: linkedhashmap
keyConvertor: fastjson
limit: 1000
remote:
default:
type: redis
keyConvertor: fastjson
valueEncoder: java
valueDecoder: java
poolConfig:
minIdle: 5
maxIdle: 20
maxTotal: 50
database: 16 # Database index used by the connection factory
host: xxx # It needs to be modified here
port: xxx # It needs to be modified here
password: xxx # It needs to be modified here
3.3 Start class annotation
@EnableMethodCache(basePackages = "com.iot.back.message")
3.4 Add a comment to the method
expire Represents the return value User object , Will be in 3600 Seconds after expired ,JetCache By default, all input parameters are used to generate cached key.
Four 、 Depend on which Jar?
- jetcache-anno-api: Definition jetcache Comments and constants , Do not pass dependencies . If you want to Cached Annotations are added to the interface , I don't want your interface jar Passing too many dependencies , You can make the interface jar rely on jetcache-anno-api.
- jetcache-core: The core api, Configure the operation completely through programming Cache, Do not rely on Spring. Two in memory cache implementations LinkedHashMapCache and CaffeineCache It also provides .
- jetcache-anno: be based on Spring Provide @Cached and @CreateCache Annotation support .
- jetcache-redis: Use jedis Provide Redis Support .
- jetcache-redis-lettuce( need JetCache2.3 Above version ): Use lettuce Provide Redis Support , Realized JetCache Interface to access cache asynchronously .
- jetcache-starter-redis:Spring Boot The way of Starter, be based on Jedis.
- jetcache-starter-redis-lettuce( need JetCache2.3 Above version ):Spring Boot The way of Starter, be based on Lettuce.
Reference documents :《JetCache Official documents 》
The end !
边栏推荐
- Matlab traverses images, string arrays and other basic operations
- Sonic云真机学习总结6 - 1.4.1服务端、agent端部署
- What is the difference between consonants and Initials? (difference between initials and consonants)
- Recent public ancestor offline practice (tarjan)
- Slope compensation
- leetcode - 287. 寻找重复数
- keras训练的H5模型转tflite
- Object memory layout
- Simple interactive operation of electron learning (III)
- Is PMP certificate really useful?
猜你喜欢
91.(cesium篇)cesium火箭发射模拟
Application of real estate management based on 3D GIS
Icml2022 | interventional contrastive learning based on meta semantic regularization
【juc学习之路第9天】屏障衍生工具
Is PMP certificate really useful?
Fully annotated SSM framework construction
Ida dynamic debugging apk
隐藏用户的创建和使用
How to write a performance test plan
Mysql——》Innodb存储引擎的索引
随机推荐
Mysql——》Innodb存储引擎的索引
flink sql 命令行 连接 yarn
mysql 学习笔记-优化之SQL优化
Burpsuite simple packet capturing tutorial [easy to understand]
地图其他篇总目录
Dark horse programmer - software testing - stage 06 2-linux and database-01-08 Chapter 1 - description of the content of the Linux operating system stage, description of the basic format and common fo
Several ways of writing main function in C
详解ThreadLocal
内存导致的电脑游戏中显示hdmi无信号 从而死机的情况
【juc学习之路第9天】屏障衍生工具
The correct way to set the bypass route
GaussDB(DWS)主动预防排查
【JetCache】JetCache的使用方法与步骤
I received a letter from CTO inviting me to interview machine learning engineer
[STM32] stm32cubemx tutorial II - basic use (new projects light up LED lights)
隐藏用户的创建和使用
Is PMP certificate really useful?
One of the basic learning of function
QT 使用FFmpeg4将argb的Qimage转换成YUV422P
Yan Rong looks at how to formulate a multi cloud strategy in the era of hybrid cloud