Refactor get() to return object if expired
Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
This commit is contained in:
parent
325c2f7b87
commit
abfba771cd
6
cache.go
6
cache.go
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue