Skip to content

Commit

Permalink
Add Clear() function
Browse files Browse the repository at this point in the history
  • Loading branch information
TwiN committed Jul 1, 2020
1 parent d7d9d1a commit 6659a52
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
```
6 changes: 6 additions & 0 deletions gocache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

0 comments on commit 6659a52

Please sign in to comment.