Fetch does not return stale items
This commit is contained in:
8
cache.go
8
cache.go
@@ -81,12 +81,12 @@ func (c *Cache) Replace(key string, value interface{}) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// Attempts to get the value from the cache and calles fetch on a miss.
|
||||
// If fetch returns an error, no value is cached and the error is returned back
|
||||
// to the caller.
|
||||
// Attempts to get the value from the cache and calles fetch on a miss (missing
|
||||
// or stale item). If fetch returns an error, no value is cached and the error
|
||||
// is returned back to the caller.
|
||||
func (c *Cache) Fetch(key string, duration time.Duration, fetch func() (interface{}, error)) (*Item, error) {
|
||||
item := c.Get(key)
|
||||
if item != nil {
|
||||
if item != nil && !item.Expired() {
|
||||
return item, nil
|
||||
}
|
||||
value, err := fetch()
|
||||
|
Reference in New Issue
Block a user