当前位置:网站首页>[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 !
边栏推荐
- Flume interview questions
- 园区全光技术选型-中篇
- flink sql 命令行 连接 yarn
- Show member variables and methods in classes in idea
- 【图像分割】2021-SegFormer NeurIPS
- MySQL MHA high availability configuration and failover
- QT 使用FFmpeg4将argb的Qimage转换成YUV422P
- Can you get a raise? Analysis on gold content of PMP certificate
- Basic knowledge of ngnix
- Internet of things RFID, etc
猜你喜欢
随机推荐
Yan Rong looks at how to formulate a multi cloud strategy in the era of hybrid cloud
Communication between browser tab pages
"The silk road is in its youth and looks at Fujian" is in the hot collection of works in the Fujian foreign youth short video competition
详解ThreadLocal
Why does blocprovider feel similar to provider?
Chapter 9 Yunji datacanvas company has been ranked top 3 in China's machine learning platform market
EasyExcel 复杂数据导出
I received a letter from CTO inviting me to interview machine learning engineer
Recent public ancestor offline practice (tarjan)
flink sql 命令行 连接 yarn
Matlab traverses images, string arrays and other basic operations
The correct way to set the bypass route
互联网的智算架构设计
mysql 学习笔记-优化之SQL优化
RestTemplate 远程调用工具类
Internet of things RFID, etc
Which securities company should we choose to open an account for flush stock? Is it safe to open an account with a mobile phone?
GenICam GenTL 标准 ver1.5(4)第五章 采集引擎
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
【MySQL】索引的创建、查看和删除






![[noip2013] building block competition [noip2018] road laying greed / difference](/img/d1/a56231cd4eb3cc1d91d8a55048ccfe.png)

