当前位置:网站首页>[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 !
边栏推荐
- 恶意软件反向关闭EDR的原理、测试和反制思考
- Design and practice of new generation cloud native database
- Basic operation of binary tree
- 黑马程序员-软件测试--06阶段2-linux和数据库-01-08第一章-linux操作系统阶段内容说明,linux命令基本格式以及常见形式的说明,操作系统的常见的分类,查看命令帮助信息方法,
- 详解LockSupport的使用
- 快乐数[环类问题之快慢指针]
- [live broadcast review] the first 8 live broadcasts of battle code Pioneer have come to a perfect end. Please look forward to the next one!
- The difference between NiO and traditional IO
- Gaussdb (DWS) active prevention and troubleshooting
- Which securities company should we choose to open an account for flush stock? Is it safe to open an account with a mobile phone?
猜你喜欢
对象内存布局
互联网的智算架构设计
【MySQL】索引的分类
Easyexcel complex data export
What is the difference between PMP and NPDP?
plantuml介绍与使用
【图像分割】2021-SegFormer NeurIPS
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
3DE 资源没东西或不对
Indicator trap: seven KPI mistakes that it leaders are prone to make
随机推荐
Airserver mobile phone third-party screen projection computer software
[live broadcast review] the first 8 live broadcasts of battle code Pioneer have come to a perfect end. Please look forward to the next one!
[noip2013] building block competition [noip2018] road laying greed / difference
Design and practice of new generation cloud native database
awoo‘s Favorite Problem(优先队列)
详解ThreadLocal
Communication between browser tab pages
Pytorch sharpening chapter | argmax and argmin functions
Business visualization - make your flowchart'run'up
Little p weekly Vol.11
Qtreeview+qabstractitemmodel custom model: the third of a series of tutorials [easy to understand]
Mysql——》索引存储模型推演
从零开始学 MySQL —数据库和数据表操作
IDA动态调试apk
详解LockSupport的使用
详解JMM
Is PMP certificate really useful?
[commercial terminal simulation solution] Shanghai daoning brings you Georgia introduction, trial and tutorial
Classify boost libraries by function
Yan Rong looks at how to formulate a multi cloud strategy in the era of hybrid cloud