fix increment/decrement in cache

This commit is contained in:
Asim Aslam
2021-05-19 14:32:12 +01:00
parent 083f223f99
commit 662d420d53

6
pkg/cache/cache.go vendored
View File

@@ -66,7 +66,7 @@ func (c *cache) Context(ctx context.Context) Cache {
return c
}
return &cache{
LRU: c.LRU,
LRU: c.LRU,
Store: c.Store,
Prefix: t,
}
@@ -156,7 +156,7 @@ func (c *cache) Increment(key string, value int64) (int64, error) {
defer c.Unlock()
var val int64
if err := c.Get(key, &val); err != nil {
if err := c.Get(key, &val); err != nil && err != ErrNotFound {
return 0, err
}
val += value
@@ -171,7 +171,7 @@ func (c *cache) Decrement(key string, value int64) (int64, error) {
defer c.Unlock()
var val int64
if err := c.Get(key, &val); err != nil {
if err := c.Get(key, &val); err != nil && err != ErrNotFound {
return 0, err
}
val -= value