Skip to content

Commit

Permalink
implemented Range method to Cache
Browse files Browse the repository at this point in the history
  • Loading branch information
logica0419 committed Jul 25, 2022
1 parent 61c503f commit 0372788
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ func (c *Cache[K, V]) Delete(key K) {
c.m.Delete(key)
}

// ForEach キャッシュの全ての要素に対して処理を行う
func (c *Cache[K, V]) ForEach(f func(key K, value V) error) (err error) {
c.m.Range(func(key, value interface{}) bool {
k, _ := key.(K)
v, _ := value.(V)

err = f(k, v)
return err == nil
})

return
}

// Reset 全てのキャッシュを削除
func (c *Cache[K, V]) Reset() {
c.m = &sync.Map{}
Expand Down

0 comments on commit 0372788

Please sign in to comment.