From 6659a52b1958c39294a735731796268572eead57 Mon Sep 17 00:00:00 2001 From: TwinProduction Date: Tue, 30 Jun 2020 23:19:56 -0400 Subject: [PATCH] Add Clear() function --- README.md | 4 +++- gocache.go | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fb42d29..d7c7396 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,9 @@ go get github.com/TwinProduction/gocache ``` ```golang -cache := NewCache().WithMaxSize(1000).WithEvictionPolicy(gocache.LeastRecentlyUsed) +cache := gocache.NewCache().WithMaxSize(1000).WithEvictionPolicy(gocache.LeastRecentlyUsed) cache.Set("key", "value") value, ok := cache.Get("key") +cache.Delete("key") +cache.Count() ``` \ No newline at end of file diff --git a/gocache.go b/gocache.go index 3f30904..aa11b67 100644 --- a/gocache.go +++ b/gocache.go @@ -87,3 +87,9 @@ func (cache *Cache) Count() int { cache.mutex.Unlock() return count } + +func (cache *Cache) Clear() { + cache.mutex.Lock() + cache.entries = make(map[string]*Entry) + cache.mutex.Unlock() +}