We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 76f1250 commit d461c5dCopy full SHA for d461c5d
cache.go
@@ -49,8 +49,19 @@ type cache struct {
49
// (DefaultExpiration), the cache's default expiration time is used. If it is -1
50
// (NoExpiration), the item never expires.
51
func (c *cache) Set(k string, x interface{}, d time.Duration) {
52
+ // "Inlining" of set
53
+ var e int64
54
+ if d == DefaultExpiration {
55
+ d = c.defaultExpiration
56
+ }
57
+ if d > 0 {
58
+ e = time.Now().Add(d).UnixNano()
59
60
c.mu.Lock()
- c.set(k, x, d)
61
+ c.items[k] = Item{
62
+ Object: x,
63
+ Expiration: e,
64
65
// TODO: Calls to mu.Unlock are currently not deferred because defer
66
// adds ~200 ns (as of go1.)
67
c.mu.Unlock()
0 commit comments