当前位置:网站首页>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]所创,转载请带上原文链接,感谢
边栏推荐
- Network security engineer Demo: the original * * is to get your computer administrator rights! 【***】
- 比特币一度突破14000美元,即将面临美国大选考验
- Process analysis of Python authentication mechanism based on JWT
- Construction of encoder decoder model with keras LSTM
- 中小微企业选择共享办公室怎么样?
- 5.4 static resource mapping
- [event center azure event hub] interpretation of error information found in event hub logs
- Brief introduction of TF flags
- Save the file directly to Google drive and download it back ten times faster
- Programmer introspection checklist
猜你喜欢
每个前端工程师都应该懂的前端性能优化总结:
TensorFlow中的Tensor是什么?
The road of C + + Learning: from introduction to mastery
Face to face Manual Chapter 16: explanation and implementation of fair lock of code peasant association lock and reentrantlock
加速「全民直播」洪流,如何攻克延时、卡顿、高并发难题?
What is the side effect free method? How to name it? - Mario
一篇文章带你了解CSS3图片边框
有了这个神器,快速告别垃圾短信邮件
Free patent download tutorial (HowNet, Espacenet)
在大规模 Kubernetes 集群上实现高 SLO 的方法
随机推荐
Electron application uses electronic builder and electronic updater to realize automatic update
Python + appium automatic operation wechat is enough
I've been rejected by the product manager. Why don't you know
Installing the consult cluster
一篇文章教会你使用Python网络爬虫下载酷狗音乐
NLP model Bert: from introduction to mastery (2)
零基础打造一款属于自己的网页搜索引擎
Filecoin主网上线以来Filecoin矿机扇区密封到底是什么意思
What problems can clean architecture solve? - jbogard
6.4 viewresolver view parser (in-depth analysis of SSM and project practice)
Skywalking series blog 1 - install stand-alone skywalking
全球疫情加速互联网企业转型,区块链会是解药吗?
How long does it take you to work out an object-oriented programming interview question from Ali school?
零基础打造一款属于自己的网页搜索引擎
[event center azure event hub] interpretation of error information found in event hub logs
Using consult to realize service discovery: instance ID customization
Face to face Manual Chapter 16: explanation and implementation of fair lock of code peasant association lock and reentrantlock
合约交易系统开发|智能合约交易平台搭建
Do not understand UML class diagram? Take a look at this edition of rural love class diagram, a learn!
Save the file directly to Google drive and download it back ten times faster