From 2f20b64c0f7804c32907227d526678e66a38368e Mon Sep 17 00:00:00 2001 From: Umputun Date: Fri, 22 May 2020 14:18:34 -0500 Subject: [PATCH] switch lcw to stable version --- backend/go.mod | 2 +- backend/go.sum | 4 ++-- .../github.com/go-pkgz/lcw/expirable_cache.go | 21 +++++++++++-------- .../go-pkgz/lcw/internal/cache/cache.go | 4 ++-- .../github.com/go-pkgz/lcw/lru_cache.go | 19 ++++++++++------- .../github.com/go-pkgz/lcw/redis_cache.go | 15 +++++++------ backend/vendor/modules.txt | 2 +- 7 files changed, 38 insertions(+), 29 deletions(-) diff --git a/backend/go.mod b/backend/go.mod index ccd62cd2..7a361874 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -14,7 +14,7 @@ require ( github.com/go-chi/render v1.0.1 github.com/go-pkgz/auth v0.10.1 github.com/go-pkgz/jrpc v0.1.0 - github.com/go-pkgz/lcw v0.5.1-0.20200509170726-dc283cfc28cf + github.com/go-pkgz/lcw v0.6.0 github.com/go-pkgz/lgr v0.7.0 github.com/go-pkgz/repeater v1.1.3 github.com/go-pkgz/rest v1.5.0 diff --git a/backend/go.sum b/backend/go.sum index 0eec86a8..b3f2b6f0 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -65,8 +65,8 @@ github.com/go-pkgz/auth v0.10.1 h1:GYf64js5n/oVEPXhRShyDDiR/oahdZOMLbxmnnGX2IU= github.com/go-pkgz/auth v0.10.1/go.mod h1:wxyQqc0UUP1jT4l6zk1r6XPcVdcgIzW2OiQ8hBEHd64= github.com/go-pkgz/jrpc v0.1.0 h1:hNg/IyfEqJcSWOKkuHw0ZwcuGc9TDp7QZREsD2ycmiM= github.com/go-pkgz/jrpc v0.1.0/go.mod h1:JxZsvoBklA50DNhELVJnJ567Rt+KrMH9rR3u515wvE8= -github.com/go-pkgz/lcw v0.5.1-0.20200509170726-dc283cfc28cf h1:lUztZWD77zDSILb3DHCpIpHxLILUmAf15aYNAEbWtIM= -github.com/go-pkgz/lcw v0.5.1-0.20200509170726-dc283cfc28cf/go.mod h1:vovP88gZLeuIWn5cm0NlgPYFyGGkv3m2OcKMOOaHhj0= +github.com/go-pkgz/lcw v0.6.0 h1:BVEZDhVMM2W719tRED3j14lGRqNmGIlnVKVeJkPRVKs= +github.com/go-pkgz/lcw v0.6.0/go.mod h1:vovP88gZLeuIWn5cm0NlgPYFyGGkv3m2OcKMOOaHhj0= github.com/go-pkgz/lgr v0.7.0 h1:S/AAPwt/RE9a5mNJskA7dGVp+Dq6SMIW6LYjG3ITxY8= github.com/go-pkgz/lgr v0.7.0/go.mod h1:yMgxU+GobMRJgIEbSzDKy/67W18S7qmGx/7BVL5AB8Q= github.com/go-pkgz/repeater v1.1.3 h1:q6+JQF14ESSy28Dd7F+wRelY4F+41HJ0LEy/szNnMiE= diff --git a/backend/vendor/github.com/go-pkgz/lcw/expirable_cache.go b/backend/vendor/github.com/go-pkgz/lcw/expirable_cache.go index f772086e..4f862efd 100644 --- a/backend/vendor/github.com/go-pkgz/lcw/expirable_cache.go +++ b/backend/vendor/github.com/go-pkgz/lcw/expirable_cache.go @@ -68,17 +68,20 @@ func (c *ExpirableCache) Get(key string, fn func() (Value, error)) (data Value, } atomic.AddInt64(&c.Misses, 1) - if c.allowed(key, data) { - if s, ok := data.(Sizer); ok { - if c.maxCacheSize > 0 && atomic.LoadInt64(&c.currentSize)+int64(s.Size()) >= c.maxCacheSize { - c.backend.DeleteExpired() - return data, nil - } - atomic.AddInt64(&c.currentSize, int64(s.Size())) - } - c.backend.Set(key, data) + if !c.allowed(key, data) { + return data, nil } + if s, ok := data.(Sizer); ok { + if c.maxCacheSize > 0 && atomic.LoadInt64(&c.currentSize)+int64(s.Size()) >= c.maxCacheSize { + c.backend.DeleteExpired() + return data, nil + } + atomic.AddInt64(&c.currentSize, int64(s.Size())) + } + + c.backend.Set(key, data) + return data, nil } diff --git a/backend/vendor/github.com/go-pkgz/lcw/internal/cache/cache.go b/backend/vendor/github.com/go-pkgz/lcw/internal/cache/cache.go index 15ef1d1f..3824c4e6 100644 --- a/backend/vendor/github.com/go-pkgz/lcw/internal/cache/cache.go +++ b/backend/vendor/github.com/go-pkgz/lcw/internal/cache/cache.go @@ -237,6 +237,6 @@ func (c *LoadingCache) purge(maxKeys int64) { } type cacheItem struct { - expiresAt time.Time - data interface{} + expiresAt time.Time + data interface{} } diff --git a/backend/vendor/github.com/go-pkgz/lcw/lru_cache.go b/backend/vendor/github.com/go-pkgz/lcw/lru_cache.go index 8c36c267..fee675d7 100644 --- a/backend/vendor/github.com/go-pkgz/lcw/lru_cache.go +++ b/backend/vendor/github.com/go-pkgz/lcw/lru_cache.go @@ -62,18 +62,21 @@ func (c *LruCache) Get(key string, fn func() (Value, error)) (data Value, err er atomic.AddInt64(&c.Misses, 1) - if c.allowed(key, data) { - c.backend.Add(key, data) + if !c.allowed(key, data) { + return data, nil + } - if s, ok := data.(Sizer); ok { - atomic.AddInt64(&c.currentSize, int64(s.Size())) - if c.maxCacheSize > 0 && atomic.LoadInt64(&c.currentSize) > c.maxCacheSize { - for atomic.LoadInt64(&c.currentSize) > c.maxCacheSize { - c.backend.RemoveOldest() - } + c.backend.Add(key, data) + + if s, ok := data.(Sizer); ok { + atomic.AddInt64(&c.currentSize, int64(s.Size())) + if c.maxCacheSize > 0 && atomic.LoadInt64(&c.currentSize) > c.maxCacheSize { + for atomic.LoadInt64(&c.currentSize) > c.maxCacheSize { + c.backend.RemoveOldest() } } } + return data, nil } diff --git a/backend/vendor/github.com/go-pkgz/lcw/redis_cache.go b/backend/vendor/github.com/go-pkgz/lcw/redis_cache.go index ced6bd36..e2deb985 100644 --- a/backend/vendor/github.com/go-pkgz/lcw/redis_cache.go +++ b/backend/vendor/github.com/go-pkgz/lcw/redis_cache.go @@ -61,13 +61,16 @@ func (c *RedisCache) Get(key string, fn func() (Value, error)) (data Value, err } atomic.AddInt64(&c.Misses, 1) - if c.allowed(key, data) { - _, setErr := c.backend.Set(key, data, c.ttl).Result() - if setErr != nil { - atomic.AddInt64(&c.Errors, 1) - return data, setErr - } + if !c.allowed(key, data) { + return data, nil } + + _, setErr := c.backend.Set(key, data, c.ttl).Result() + if setErr != nil { + atomic.AddInt64(&c.Errors, 1) + return data, setErr + } + return data, nil } diff --git a/backend/vendor/modules.txt b/backend/vendor/modules.txt index 3ff1d52a..775309eb 100644 --- a/backend/vendor/modules.txt +++ b/backend/vendor/modules.txt @@ -84,7 +84,7 @@ github.com/go-pkgz/auth/token # github.com/go-pkgz/jrpc v0.1.0 ## explicit github.com/go-pkgz/jrpc -# github.com/go-pkgz/lcw v0.5.1-0.20200509170726-dc283cfc28cf +# github.com/go-pkgz/lcw v0.6.0 ## explicit github.com/go-pkgz/lcw github.com/go-pkgz/lcw/internal/cache