Skip to content

Commit

Permalink
implement GetAll on MCache
Browse files Browse the repository at this point in the history
  • Loading branch information
knbr13 committed Apr 6, 2024
1 parent fadbe1c commit dddc72f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions mcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,18 @@ func (c *MCache[K, V]) Get(k K) (v V, b bool) {
return val.value, ok
}

func (c *MCache[K, V]) GetAll() map[K]V {
c.mu.RLock()
defer c.mu.RUnlock()
m := make(map[K]V)
for k, v := range c.m {
if v.expireAt == nil || !v.expireAt.Before(time.Now()) {
m[k] = v.value
}
}
return m
}

func (c *MCache[K, V]) Delete(k K) {
c.mu.Lock()
defer c.mu.Unlock()
Expand Down

0 comments on commit dddc72f

Please sign in to comment.