Update cache.go

This commit is contained in:
GITSRC 2020-04-16 17:29:30 +08:00 committed by GitHub
parent 46f4078530
commit 6919aa7277
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 11 deletions

View File

@ -50,18 +50,19 @@ type cache struct {
// (NoExpiration), the item never expires.
func (c *cache) Set(k string, x interface{}, d time.Duration) {
// "Inlining" of set
var e int64
if d == DefaultExpiration {
d = c.defaultExpiration
}
if d > 0 {
e = time.Now().Add(d).UnixNano()
}
// var e int64
// if d == DefaultExpiration {
// d = c.defaultExpiration
// }
// if d > 0 {
// e = time.Now().Add(d).UnixNano()
// }
c.mu.Lock()
c.items[k] = Item{
Object: x,
Expiration: e,
}
// c.items[k] = Item{
// Object: x,
// Expiration: e,
// }
c.set(k, x, d)
// TODO: Calls to mu.Unlock are currently not deferred because defer
// adds ~200 ns (as of go1.)
c.mu.Unlock()