Skip to content

Commit

Permalink
将 NewLoader 改成私有的
Browse files Browse the repository at this point in the history
  • Loading branch information
FishGoddess committed Jan 13, 2024
1 parent 5a62ec8 commit 0426d61
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lfu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions load.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type testLoadCache struct {

func newTestLoadCache(singleflight bool) Cache {
cache := &testLoadCache{
loader: NewLoader(singleflight),
loader: newLoader(singleflight),
}

return cache
Expand Down Expand Up @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion lru.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion standard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0426d61

Please sign in to comment.