fix: expose the Offset property to allow external modifications
This commit is contained in:
parent
7fa92f927a
commit
4f8e984df6
7
client/cache/random_expired_cache.go
vendored
7
client/cache/random_expired_cache.go
vendored
@ -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
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user