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.
|
// (NoExpiration), the item never expires.
|
||||||
func (c *cache) Set(k string, x interface{}, d time.Duration) {
|
func (c *cache) Set(k string, x interface{}, d time.Duration) {
|
||||||
// "Inlining" of set
|
// "Inlining" of set
|
||||||
var e int64
|
// var e int64
|
||||||
if d == DefaultExpiration {
|
// if d == DefaultExpiration {
|
||||||
d = c.defaultExpiration
|
// d = c.defaultExpiration
|
||||||
}
|
// }
|
||||||
if d > 0 {
|
// if d > 0 {
|
||||||
e = time.Now().Add(d).UnixNano()
|
// e = time.Now().Add(d).UnixNano()
|
||||||
}
|
// }
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
c.items[k] = Item{
|
// c.items[k] = Item{
|
||||||
Object: x,
|
// Object: x,
|
||||||
Expiration: e,
|
// Expiration: e,
|
||||||
}
|
// }
|
||||||
|
c.set(k, x, d)
|
||||||
// TODO: Calls to mu.Unlock are currently not deferred because defer
|
// TODO: Calls to mu.Unlock are currently not deferred because defer
|
||||||
// adds ~200 ns (as of go1.)
|
// adds ~200 ns (as of go1.)
|
||||||
c.mu.Unlock()
|
c.mu.Unlock()
|
||||||
|
|
Loading…
Reference in New Issue