当前位置:网站首页>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)
}
边栏推荐
- WPF做登陆界面
- Resolve merge fields in salesforce
- Using the vlookup method in salesforce validation rule
- Profiles vs Permission Sets
- golang worker池
- Salesforce File Share and Security
- Summer Challenge [FFH] real time chat room websocket practice
- PostgreSQL 14 支持winserver2022吗?
- mysql解决唯一索引重复导致的插入失败问题
- 知物由学 | 小游戏的安全风险在哪里?
猜你喜欢

Application of knowing things and learning | correlation graph analysis in anti cheating business

知物由学 | APP大瘦身,新一代AAB框架下的安全加固之道

Operation of simulated examination platform for 2022 low voltage electrician examination questions

最新大厂高级面试题 必备
![[MCU] 2.3 CPU of AT89S52](/img/4c/7b9d235bf8a919339d75a7ec95789f.png)
[MCU] 2.3 CPU of AT89S52

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

Code compliance: five reasons why developers use helix QAC

【cf】#681 A. Kids Seating (Div. 2, based on VK Cup 2019-2020 - Final)
知物由学 | 小游戏的安全风险在哪里?

机器学习之评价指标(二)——分类评价指标
随机推荐
Profiles vs Permission Sets
Getting started with shell programming base
年终总结模板
Salesforce certified sharing and visibility Designer (su20) certification examination summary
细数国产接口协作平台的六把武器!
Evaluation index of machine learning (I) -- regression evaluation index
Convolutional neural network -- Translation of yolov1 thesis
机器学习之评价指标(一)——回归评价指标
What's the use of games| Game application value research case collection
Layout of flutter
TCP的连接状态标识 (SYN, FIN, ACK, PSH, RST, URG)
MySQL creates a student table and queries grades
最新大厂高级面试题 必备
golang worker池
How can we carry out NLP cross language knowledge transfer?
【Codeforces】 A. Computer Game
How to learn C language? This article gives you the complete answer
【Codeforces】 B. Make it Divisible by 25
org.gradle.api.UncheckedIOException: Could not load properties for module ‘gradle-kotlin-dsl‘ from C
卷积神经网络——YOLOV1论文翻译