Skip to content

Commit 0372788

Browse files
committed
implemented Range method to Cache
1 parent 61c503f commit 0372788

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

cache.go

+13
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,19 @@ func (c *Cache[K, V]) Delete(key K) {
6363
c.m.Delete(key)
6464
}
6565

66+
// ForEach キャッシュの全ての要素に対して処理を行う
67+
func (c *Cache[K, V]) ForEach(f func(key K, value V) error) (err error) {
68+
c.m.Range(func(key, value interface{}) bool {
69+
k, _ := key.(K)
70+
v, _ := value.(V)
71+
72+
err = f(k, v)
73+
return err == nil
74+
})
75+
76+
return
77+
}
78+
6679
// Reset 全てのキャッシュを削除
6780
func (c *Cache[K, V]) Reset() {
6881
c.m = &sync.Map{}

0 commit comments

Comments
 (0)