Merge 56403766d8
into 46f4078530
This commit is contained in:
commit
bf87505cd1
28
cache.go
28
cache.go
|
@ -927,6 +927,34 @@ type keyAndValue struct {
|
||||||
value interface{}
|
value interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *cache) Expire(k string, d time.Duration) error {
|
||||||
|
c.Lock()
|
||||||
|
v, found := c.items[k]
|
||||||
|
if !found || v.Expired() {
|
||||||
|
c.Unlock()
|
||||||
|
return fmt.Errorf("key %s not found.", k)
|
||||||
|
}
|
||||||
|
|
||||||
|
e := time.Now().Add(d)
|
||||||
|
v.Expiration = &e
|
||||||
|
|
||||||
|
c.Unlock()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *cache) ExpireAt(k string, expire *time.Time) error {
|
||||||
|
c.Lock()
|
||||||
|
v, found := c.items[k]
|
||||||
|
if !found || v.Expired() {
|
||||||
|
c.Unlock()
|
||||||
|
return fmt.Errorf("key %s not found.", k)
|
||||||
|
}
|
||||||
|
|
||||||
|
v.Expiration = expire
|
||||||
|
c.Unlock()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Delete all expired items from the cache.
|
// Delete all expired items from the cache.
|
||||||
func (c *cache) DeleteExpired() {
|
func (c *cache) DeleteExpired() {
|
||||||
var evictedItems []keyAndValue
|
var evictedItems []keyAndValue
|
||||||
|
|
Loading…
Reference in New Issue