Update cache.go
This commit is contained in:
parent
46f4078530
commit
6919aa7277
23
cache.go
23
cache.go
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue