当前位置:网站首页>Jetcache buried some of the operation, you can't accept it
Jetcache buried some of the operation, you can't accept it
2020-11-06 01:28:00 【Yin Jihuan】
Explain the background
Caching is an absolute weapon to deal with high concurrency , As many business scenarios allow , You can use caching to provide performance .
Since the cache is used , It's essential to monitor the cache . For example, cache loading takes time , New time and so on .
stay JetCache The embedded point operation is carried out in the , about Redis There's no problem with caching , After that Key Is a full , The whole is Cache Of name+key, Here's the picture :

Except yes Redis Cache as a buried point , And for the local cache Caffeine We also did some embedding operations , And found that Caffeine There's something wrong with the burial point of , The problem lies in Cache Of name lost , Here's the picture :

Then I went to the official nail group and asked the maintenance personnel , Let me upgrade the version . Then I upgraded to the latest 2.6.0 Not yet. , This is not a pit for me !
Find out the reason
Do it yourself , Have ample food and clothing . Just look at the code , First of all to see Redis why Cache name There is no loss , as a result of Redis Of Config There is keyPrefix, Here's the picture :

Then I'm right Redis When operating , Will build the cache Key, structure Key I'll take it with me keyPrefix, therefore Redis Of Key It's normal .
com.alicp.jetcache.external.AbstractExternalCache
public byte[] buildKey(K key) {try {Object newKey = key;if (key instanceof byte[]) {newKey = key;} else if (key instanceof String) {newKey = key;} else if (this.config.getKeyConvertor() != null) {newKey = this.config.getKeyConvertor().apply(key);}return ExternalKeyUtil.buildKeyAfterConvert(newKey, this.config.getKeyPrefix());} catch (IOException var3) {throw new CacheException(var3);}}
Then come to see Caffeine Of config There is no Keyprefix Of , Here's the picture :

And then building the cache Key When , No Keyprefix, So the problem is here .
com.alicp.jetcache.embedded.AbstractEmbeddedCache
public Object buildKey(K key) {if (key == null) {return null;} else {Object newKey = key;Function<K, Object> keyConvertor = this.config.getKeyConvertor();if (keyConvertor != null) {newKey = keyConvertor.apply(key);}return newKey;}}
RedisCacheConfig Inherited ExternalCacheConfig,ExternalCacheConfig Inherited CacheConfig.
keyPrefix It's defined in ExternalCacheConfig in .

and EmbeddedCacheConfig Only inherited CacheConfig, So naturally it doesn't have keyPrefix Field .

Solution
The reason has been found out , It must be possible to solve it . The problem is that it's an open source framework , It's not your own company's internal code . But you can also clone the source code directly , To transform , Then package and publish it to your own private server .
take EmbeddedCacheConfig Also inherited ExternalCacheConfig It can be keyPrefix Go through it , And then in buildKey Where to splice .
There is also a more opportunistic approach , You don't have to change the configuration class relationship , stay config There is monitors This information , It stores the cache monitoring information , It mainly refers to the operation type corresponding to the record cache ,GET, PUT such , Then there is the execution time of each operation , The number of operations and other statistical information , Eventually, a thread will periodically output this information to the log .
So we can get monitors Medium cacheName Solve the problem in the near future .

private String getCacheName() {List<CacheMonitor> monitors = config.getMonitors();if (CollectionUtils.isEmpty(monitors)) {return "";}DefaultCacheMonitor cacheMonitor = (DefaultCacheMonitor) monitors.get(0);String cacheName = cacheMonitor.getCacheName();return cacheName;}
Function code : https://github.com/yinjihuan/kitty
About author : Yin Jihuan , Simple technology enthusiasts ,《Spring Cloud Microservices - Full stack technology and case analysis 》, 《Spring Cloud Microservices introduction Actual combat and advanced 》 author , official account Ape world Originator . Personal wechat jihuan900 , Welcome to hook up with .
I have compiled a complete set of learning materials , Those who are interested can search through wechat 「 Ape world 」, Reply key 「 Learning materials 」 Get what I've sorted out Spring Cloud,Spring Cloud Alibaba,Sharding-JDBC Sub database and sub table , Task scheduling framework XXL-JOB,MongoDB, Reptiles and other related information .

版权声明
本文为[Yin Jihuan]所创,转载请带上原文链接,感谢
边栏推荐
- High availability cluster deployment of jumpserver: (6) deployment of SSH agent module Koko and implementation of system service management
- 钻石标准--Diamond Standard
- 关于Kubernetes 与 OAM 构建统一、标准化的应用管理平台知识!(附网盘链接)
- html
- 2019年的一个小目标,成为csdn的博客专家,纪念一下
- Not long after graduation, he earned 20000 yuan from private work!
- Advanced Vue component pattern (3)
- axios学习笔记(二):轻松弄懂XHR的使用及如何封装简易axios
- Tool class under JUC package, its name is locksupport! Did you make it?
- 一篇文章带你了解CSS3圆角知识
猜你喜欢

MeterSphere开发者手册

Not long after graduation, he earned 20000 yuan from private work!

Pattern matching: The gestalt approach一种序列的文本相似度方法

Filecoin的经济模型与未来价值是如何支撑FIL币价格破千的

2019年的一个小目标,成为csdn的博客专家,纪念一下

In order to save money, I learned PHP in one day!

Mac installation hanlp, and win installation and use

Free patent download tutorial (HowNet, Espacenet)

NLP model Bert: from introduction to mastery (1)

Network security engineer Demo: the original * * is to get your computer administrator rights! 【***】
随机推荐
This article will introduce you to jest unit test
零基础打造一款属于自己的网页搜索引擎
How to use parameters in ES6
关于Kubernetes 与 OAM 构建统一、标准化的应用管理平台知识!(附网盘链接)
Python download module to accelerate the implementation of recording
Filecoin的经济模型与未来价值是如何支撑FIL币价格破千的
Building and visualizing decision tree with Python
MeterSphere开发者手册
Python filtering sensitive word records
Did you blog today?
In order to save money, I learned PHP in one day!
ES6学习笔记(二):教你玩转类的继承和类的对象
Advanced Vue component pattern (3)
Skywalking series blog 2-skywalking using
[C / C + + 1] clion configuration and running C language
How to encapsulate distributed locks more elegantly
前端基础牢记的一些操作-Github仓库管理
至联云解析:IPFS/Filecoin挖矿为什么这么难?
The choice of enterprise database is usually decided by the system architect - the newstack
钻石标准--Diamond Standard