diff --git a/HISTORY.md b/HISTORY.md index badde72..6d48994 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -4,7 +4,7 @@ > 此版本发布于 2024-01-13 -* 受小徒弟的灵感激发,进行 Loader 代码的调整 +* 受小徒弟的灵感激发,进行 loader 代码的调整 * 把 cache 结构去掉,精简这部分设计 ### v0.5.0 diff --git a/cache_test.go b/cache_test.go index 7abd5cc..72413e7 100644 --- a/cache_test.go +++ b/cache_test.go @@ -27,7 +27,7 @@ const ( type testCache struct { *config - loader *Loader + loader *loader count int32 } diff --git a/lfu.go b/lfu.go index 7a04e57..d4fd977 100644 --- a/lfu.go +++ b/lfu.go @@ -28,7 +28,7 @@ type lfuCache struct { itemHeap *heap.Heap lock sync.RWMutex - loader *Loader + loader *loader } func newLFUCache(conf *config) Cache { diff --git a/load.go b/load.go index 5af0370..a349ea1 100644 --- a/load.go +++ b/load.go @@ -21,15 +21,15 @@ import ( flight "github.com/FishGoddess/cachego/pkg/singleflight" ) -// Loader loads values from somewhere. -type Loader struct { +// loader loads values from somewhere. +type loader struct { group *flight.Group } // NewLoader creates a loader. // It also creates a singleflight group to call load if singleflight is true. -func NewLoader(singleflight bool) *Loader { - loader := new(Loader) +func NewLoader(singleflight bool) *loader { + loader := new(loader) if singleflight { loader.group = flight.NewGroup(mapInitialCap) @@ -39,7 +39,7 @@ func NewLoader(singleflight bool) *Loader { } // Load loads a value of key with ttl and returns an error if failed. -func (l *Loader) Load(key string, ttl time.Duration, load func() (value interface{}, err error)) (value interface{}, err error) { +func (l *loader) Load(key string, ttl time.Duration, load func() (value interface{}, err error)) (value interface{}, err error) { if load == nil { return nil, errors.New("cachego: load function is nil in loader") } @@ -52,7 +52,7 @@ func (l *Loader) Load(key string, ttl time.Duration, load func() (value interfac } // Reset resets loader to initial status which is like a new loader. -func (l *Loader) Reset() { +func (l *loader) Reset() { if l.group != nil { l.group.Reset() } diff --git a/load_test.go b/load_test.go index 92fbf09..21295eb 100644 --- a/load_test.go +++ b/load_test.go @@ -26,7 +26,7 @@ type testLoadCache struct { value interface{} ttl time.Duration - loader *Loader + loader *loader } func newTestLoadCache(singleflight bool) Cache { diff --git a/lru.go b/lru.go index 40bef21..d639bed 100644 --- a/lru.go +++ b/lru.go @@ -27,7 +27,7 @@ type lruCache struct { elementList *list.List lock sync.RWMutex - loader *Loader + loader *loader } func newLRUCache(conf *config) Cache { diff --git a/standard.go b/standard.go index b2fa599..f99a8ad 100644 --- a/standard.go +++ b/standard.go @@ -25,7 +25,7 @@ type standardCache struct { entries map[string]*entry lock sync.RWMutex - loader *Loader + loader *loader } func newStandardCache(conf *config) Cache {