Skip to content

Commit

Permalink
Extract Lock/Unlock from shard (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg authored and janisz committed Sep 20, 2017
1 parent 897acc1 commit aa76879
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
2 changes: 2 additions & 0 deletions bigcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit aa76879

Please sign in to comment.