go-cache
go-cache copied to clipboard
Question
Is there any reason for not using defer when unlocking mutex?
func (c *cache) Get(k string) (interface{}, bool) {
c.mu.RLock()
defer c.mu.RUnlock()
// "Inlining" of get and Expired
item, found := c.items[k]
if !found {
return nil, false
}
if item.Expiration > 0 {
if time.Now().UnixNano() > item.Expiration {
return nil, false
}
}
return item.Object, true
}
It used to have a reasonably significant performance impact. That was improved a few Go versions ago, and now the performance impact is negligible (I benchmarked this for my fork).
Note this package doesn't seem maintained; I have a fork at https://github.com/arp242/zcache with some fixes.