Skip to content

Commit

Permalink
add c.Keys
Browse files Browse the repository at this point in the history
  • Loading branch information
knbr13 committed May 22, 2024
1 parent 7815019 commit 64cb5d2
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lru_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,21 @@ func (src *LRUCache[K, V]) CopyTo(dst *LRUCache[K, V]) {
}
}

func (c *LRUCache[K, V]) Keys() []K {
c.mu.RLock()
defer c.mu.RUnlock()

keys := make([]K, 0, c.Count())

for k, v := range c.m {
if v.Value.(*lruItem[K, V]).expireAt == nil || !v.Value.(*lruItem[K, V]).expireAt.Before(time.Now()) {
keys = append(keys, k)
}
}

return keys
}

func (c *LRUCache[K, V]) AllKeys() []K {
c.mu.RLock()
defer c.mu.RUnlock()
Expand Down

0 comments on commit 64cb5d2

Please sign in to comment.