From 4f8e984df652a78473d11934d88e2c41f3a3e391 Mon Sep 17 00:00:00 2001 From: kevinzeng Date: Tue, 28 Jun 2022 12:45:37 +0800 Subject: [PATCH] fix: expose the Offset property to allow external modifications --- client/cache/random_expired_cache.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/client/cache/random_expired_cache.go b/client/cache/random_expired_cache.go index eeebf880..59b3d2ad 100644 --- a/client/cache/random_expired_cache.go +++ b/client/cache/random_expired_cache.go @@ -27,12 +27,12 @@ type RandomExpireCacheOption func(*RandomExpireCache) // Cache random time offset expired type RandomExpireCache struct { Cache - offset func() time.Duration + Offset func() time.Duration } // Put random time offset expired func (rec *RandomExpireCache) Put(ctx context.Context, key string, val interface{}, timeout time.Duration) error { - timeout += rec.offset() + timeout += rec.Offset() return rec.Cache.Put(ctx, key, val, timeout) } @@ -43,6 +43,9 @@ func NewRandomExpireCache(adapter Cache, opts ...RandomExpireCacheOption) Cache for _, fn := range opts { fn(&rec) } + if rec.Offset == nil { + rec.Offset = defaultExpiredFunc + } return &rec }