|
|
@ -34,8 +34,6 @@ type Cache struct {
|
|
|
|
type cache struct {
|
|
|
|
type cache struct {
|
|
|
|
DefaultExpiration time.Duration
|
|
|
|
DefaultExpiration time.Duration
|
|
|
|
Items map[string]*Item
|
|
|
|
Items map[string]*Item
|
|
|
|
// TODO: Calls to mu.Unlock are currently not deferred because defer
|
|
|
|
|
|
|
|
// adds ~200 ns (as of 792c7561af4b+ tip.)
|
|
|
|
|
|
|
|
mu sync.Mutex
|
|
|
|
mu sync.Mutex
|
|
|
|
janitor *janitor
|
|
|
|
janitor *janitor
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -45,6 +43,8 @@ type cache struct {
|
|
|
|
func (c *cache) Set(k string, x interface{}, d time.Duration) {
|
|
|
|
func (c *cache) Set(k string, x interface{}, d time.Duration) {
|
|
|
|
c.mu.Lock()
|
|
|
|
c.mu.Lock()
|
|
|
|
c.set(k, x, d)
|
|
|
|
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()
|
|
|
|
c.mu.Unlock()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|