From 0426d612bbe51324ae505d4919da8443cd9e2aab Mon Sep 17 00:00:00 2001 From: FishGoddess <1149062639@qq.com> Date: Sat, 13 Jan 2024 21:03:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=20NewLoader=20=E6=94=B9=E6=88=90?= =?UTF-8?q?=E7=A7=81=E6=9C=89=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lfu.go | 2 +- load.go | 4 ++-- load_test.go | 6 +++--- lru.go | 2 +- standard.go | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lfu.go b/lfu.go index d4fd977..1705f4b 100644 --- a/lfu.go +++ b/lfu.go @@ -40,7 +40,7 @@ func newLFUCache(conf *config) Cache { config: conf, itemMap: make(map[string]*heap.Item, mapInitialCap), itemHeap: heap.New(sliceInitialCap), - loader: NewLoader(conf.singleflight), + loader: newLoader(conf.singleflight), } return cache diff --git a/load.go b/load.go index a349ea1..b5e3f76 100644 --- a/load.go +++ b/load.go @@ -26,9 +26,9 @@ type loader struct { group *flight.Group } -// NewLoader creates a loader. +// newLoader creates a loader. // It also creates a singleflight group to call load if singleflight is true. -func NewLoader(singleflight bool) *loader { +func newLoader(singleflight bool) *loader { loader := new(loader) if singleflight { diff --git a/load_test.go b/load_test.go index 21295eb..0b473f9 100644 --- a/load_test.go +++ b/load_test.go @@ -31,7 +31,7 @@ type testLoadCache struct { func newTestLoadCache(singleflight bool) Cache { cache := &testLoadCache{ - loader: NewLoader(singleflight), + loader: newLoader(singleflight), } return cache @@ -69,12 +69,12 @@ func (tlc *testLoadCache) Load(key string, ttl time.Duration, load func() (value // go test -v -cover -count=1 -test.cpu=1 -run=^TestNewLoader$ func TestNewLoader(t *testing.T) { - loader := NewLoader(false) + loader := newLoader(false) if loader.group != nil { t.Fatalf("loader.group %+v != nil", loader.group) } - loader = NewLoader(true) + loader = newLoader(true) if loader.group == nil { t.Fatal("loader.group == nil") } diff --git a/lru.go b/lru.go index d639bed..f023c77 100644 --- a/lru.go +++ b/lru.go @@ -39,7 +39,7 @@ func newLRUCache(conf *config) Cache { config: conf, elementMap: make(map[string]*list.Element, mapInitialCap), elementList: list.New(), - loader: NewLoader(conf.singleflight), + loader: newLoader(conf.singleflight), } return cache diff --git a/standard.go b/standard.go index f99a8ad..83dd0ad 100644 --- a/standard.go +++ b/standard.go @@ -32,7 +32,7 @@ func newStandardCache(conf *config) Cache { cache := &standardCache{ config: conf, entries: make(map[string]*entry, mapInitialCap), - loader: NewLoader(conf.singleflight), + loader: newLoader(conf.singleflight), } return cache