Skip to content

Commit

Permalink
将 Loader 改成 loader 私有的
Browse files Browse the repository at this point in the history
  • Loading branch information
FishGoddess committed Jan 13, 2024
1 parent fd7f297 commit 5a62ec8
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

> 此版本发布于 2024-01-13
* 受小徒弟的灵感激发,进行 Loader 代码的调整
* 受小徒弟的灵感激发,进行 loader 代码的调整
* 把 cache 结构去掉,精简这部分设计

### v0.5.0
Expand Down
2 changes: 1 addition & 1 deletion cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const (

type testCache struct {
*config
loader *Loader
loader *loader

count int32
}
Expand Down
2 changes: 1 addition & 1 deletion lfu.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type lfuCache struct {
itemHeap *heap.Heap
lock sync.RWMutex

loader *Loader
loader *loader
}

func newLFUCache(conf *config) Cache {
Expand Down
12 changes: 6 additions & 6 deletions load.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
}
Expand All @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type testLoadCache struct {
value interface{}
ttl time.Duration

loader *Loader
loader *loader
}

func newTestLoadCache(singleflight bool) Cache {
Expand Down
2 changes: 1 addition & 1 deletion lru.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type lruCache struct {
elementList *list.List
lock sync.RWMutex

loader *Loader
loader *loader
}

func newLRUCache(conf *config) Cache {
Expand Down
2 changes: 1 addition & 1 deletion standard.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type standardCache struct {
entries map[string]*entry
lock sync.RWMutex

loader *Loader
loader *loader
}

func newStandardCache(conf *config) Cache {
Expand Down

0 comments on commit 5a62ec8

Please sign in to comment.