update lru as needed

This commit is contained in:
Asim Aslam
2021-05-19 15:05:32 +01:00
parent bdfb1d3d4d
commit 6bddf4d6db

10
pkg/cache/cache.go vendored
View File

@@ -110,6 +110,16 @@ func (c *cache) Get(key string, val interface{}) error {
if err := json.Unmarshal(recs[0].Value, val); err != nil {
return err
}
// put it in the cache for future use
// set in the lru
rec := recs[0]
expires := time.Time{}
if rec.Expiry > time.Duration(0) {
expires = time.Now().Add(rec.Expiry)
}
c.LRU.Add(rec.Key, &item{key: rec.Key, val: rec.Value, expires: expires})
return nil
}