This commit is contained in:
Berk Gokden 2020-11-18 22:48:09 +01:00 committed by GitHub
commit 9d960c75bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 0 deletions

View File

@ -922,6 +922,27 @@ func (c *cache) delete(k string) (interface{}, bool) {
return nil, false
}
func (c *cache) IncrementExpiration(k string, d time.Duration) error {
c.mu.Lock()
v, found := c.items[k]
if !found || v.Expired() {
c.mu.Unlock()
return fmt.Errorf("key %s not found.", k)
}
var e int64
if d == DefaultExpiration {
d = c.defaultExpiration
}
if d > 0 {
e = time.Now().Add(d).UnixNano()
}
v.Expiration = e
c.mu.Unlock()
return nil
}
type keyAndValue struct {
key string
value interface{}