一 背景
在上一遍文章中,讲到了关于singleflight的用法:[Golang源码:singleflight分析(一)];主要的作用就是为了防止缓存击穿;这篇文章,我们来分析它的源码。
二 数据结构定义
在singleflight源码里面,定义了三个最主要的结构:
// Group represents a class of work and forms a namespace in
// which units of work can be executed with duplicate suppression.
type Group[T any] struct {
mu sync.Mutex // protects m
m map