Skip to content

Commit

Permalink
mutex-lock only when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
knbr13 committed May 19, 2024
1 parent 5f2250a commit 6ebd903
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,13 @@ func (c *MCache[K, V]) expireKeys() {
for {
select {
case <-ticker.C:
c.mu.Lock()
for k, v := range c.m {
if v.expireAt != nil && v.expireAt.Before(time.Now()) {
c.mu.Lock()
delete(c.m, k)
c.mu.Unlock()
}
}
c.mu.Unlock()
case <-c.stopCh:
return
}
Expand Down

0 comments on commit 6ebd903

Please sign in to comment.