Refactor get() to return object if expired

Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
This commit is contained in:
Sylvain Rabot 2019-02-17 01:08:58 +01:00
parent 325c2f7b87
commit abfba771cd
1 changed files with 5 additions and 1 deletions

View File

@ -165,6 +165,10 @@ func (c *cache) GetWithExpiration(k string) (interface{}, time.Time, bool) {
return item.Object, time.Time{}, true
}
// get returns an item from the cache
// key found and item not expired => (value, true)
// key found and item expired => (value, false)
// key not found => (nil, false)
func (c *cache) get(k string) (interface{}, bool) {
item, found := c.items[k]
if !found {
@ -173,7 +177,7 @@ func (c *cache) get(k string) (interface{}, bool) {
// "Inlining" of Expired
if item.Expiration > 0 {
if time.Now().UnixNano() > item.Expiration {
return nil, false
return item.Object, false
}
}
return item.Object, true