当前位置:网站首页>Golang concurrent cache breakdown or merge request
Golang concurrent cache breakdown or merge request
2022-07-27 18:10:00 【gitxuzan_】
package main
import (
"golang.org/x/sync/singleflight"
"log"
"time"
)
func main() {
var singleSetCache singleflight.Group
getAndSetCache := func(requestID int, cacheKey string) (string, error) {
value, _, _ := singleSetCache.Do(cacheKey, func() (ret interface{
}, err error) {
//do Input key, You can use cached key, So the same cache , Only one program will read DB
log.Printf("requestid Do it once %v ", requestID)
return "VALUE", nil
})
return value.(string), nil
}
cacheKey := "cacheKey"
for i := 1; i < 10; i++ {
// Simulate multiple concurrent requests
go func(requestID int) {
value, _ := getAndSetCache(requestID, cacheKey)
//_ = value
log.Printf("requestID %v get value : %v", requestID, value)
}(i)
}
time.Sleep(20 * time.Second)
}
边栏推荐
- [introduction to database system (Wang Shan)] Chapter 11 concurrency control
- Soul 1: why is es more suitable for complex condition search than MySQL?
- Wechat applet realizes location map display and introduces map map without navigation
- MySQL adds users and grants query only permission
- Notes on standardized management of "ancestral warehouse" of meituan meal
- Getting started with shell programming base
- Operation of simulated examination platform for 2022 low voltage electrician examination questions
- 卷积神经网络——SSD论文翻译
- Wechat applet cloud function batch delete multiple data error: errcode: -502005 database collection not exists
- Hutool array tool
猜你喜欢

WPF makes login interface

登录页面tableLayout(表格布局)
知物由学 | SO加固如何提升Android应用的安全性?
How to improve the security of Android applications?

卷积神经网络——从R-CNN,Fast R-CNN到Faster R-CNN,Mask R-CNN

Understand │ what is cross domain? How to solve cross domain problems?

Interview FAQs 12

vue使用keep-alive实现页面缓存

Class not found: “com.parkManagement.dao.DaoTest 测试找不到测试类

施耐德电气、欧莱雅等企业巨头如何开放式创新?DEMO WORLD世界创新峰会揭秘
随机推荐
In the first week of June, risk control of e-shield business paid attention to 15 institutions such as New Oriental XRS, which were fined
工信部再治数据安全,网易易盾“隐私合规”守住企业经营底线
Likeshop takeout ordering system "100% open source without encryption"
Bubble sorting in JS
【云图说】 第249期 移动应用安全服务—App的体检中心,全面检测,安全上路!
快速获取网站媒体资源方法
CPU introduction
hutool- 数字计算
WebDriverException( selenium.common.exceptions.WebDriverException: Message: ‘chromedriver‘ executabl
Resolve merge fields in salesforce
知物由学 | SO加固如何提升Android应用的安全性?
Behind every piece of information you collect, you can't live without TA
Fast parsing combined with Huatu document encryption software
The latest advanced interview questions for big factories are necessary
Compilation and testing of raspberry pie driver code
WPF做登陆界面
fragmentTransaction.replace第二个参数报错
EF框架简介
ts学习笔记-class
How can we carry out NLP cross language knowledge transfer?