From aa76879d59fa5d93c43680238227dbf7a53f5c28 Mon Sep 17 00:00:00 2001 From: Oleg Kovalov Date: Wed, 20 Sep 2017 17:31:57 +0200 Subject: [PATCH] Extract Lock/Unlock from shard (#47) --- bigcache.go | 2 ++ shard.go | 4 ---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/bigcache.go b/bigcache.go index a4f41e2f..93a9b45d 100644 --- a/bigcache.go +++ b/bigcache.go @@ -134,7 +134,9 @@ func (c *BigCache) Set(key string, entry []byte) error { // Reset empties all cache shards func (c *BigCache) Reset() error { for _, shard := range c.shards { + shard.lock.Lock() shard.reset(c.config) + shard.lock.Unlock() } return nil diff --git a/shard.go b/shard.go index 6dd14e4d..996f10e2 100644 --- a/shard.go +++ b/shard.go @@ -28,13 +28,9 @@ func (s *cacheShard) removeOldestEntry() error { } func (s *cacheShard) reset(config Config) { - s.lock.Lock() - s.hashmap = make(map[uint64]uint32, config.initialShardSize()) s.entryBuffer = make([]byte, config.MaxEntrySize+headersSizeInBytes) s.entries.Reset() - - s.lock.Unlock() } func (s *cacheShard) len() int {