From 6b7005b04fcb55b8ce54311ac86e6342772fefd3 Mon Sep 17 00:00:00 2001 From: Santi Date: Sun, 3 Nov 2019 11:41:21 +0100 Subject: [PATCH] Add keys method --- cache.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cache.go b/cache.go index db88d2f..bf817b3 100644 --- a/cache.go +++ b/cache.go @@ -1034,6 +1034,16 @@ func (c *cache) LoadFile(fname string) error { return fp.Close() } +func (c *cache) Keys() []string { + c.mu.RLock() + defer c.mu.RUnlock() + keys := make([]string, 0, len(c.items)) + for k := range c.items { + keys = append(keys, k) + } + return keys +} + // Copies all unexpired items in the cache into a new map and returns it. func (c *cache) Items() map[string]Item { c.mu.RLock()