diff --git a/modules/cache/context.go b/modules/cache/context.go index 5f0ca81e8d..f9bdf52044 100644 --- a/modules/cache/context.go +++ b/modules/cache/context.go @@ -63,9 +63,9 @@ func (cc *cacheContext) isDiscard() bool { } // cacheContextLifetime is the max lifetime of cacheContext. -// Since cacheContext is used to cache data in a request level context, 10s is enough. -// If a cacheContext is used more than 10s, it's probably misuse. -const cacheContextLifetime = 10 * time.Second +// Since cacheContext is used to cache data in a request level context, 5 minutes is enough. +// If a cacheContext is used more than 5 minutes, it's probably misuse. +const cacheContextLifetime = 5 * time.Minute var timeNow = time.Now @@ -133,7 +133,7 @@ func GetContextData(ctx context.Context, tp, key any) any { if c.Expired() { // The warning means that the cache context is misused for long-life task, // it can be resolved with WithNoCacheContext(ctx). - log.Warn("cache context is expired, may be misused for long-life tasks: %v", c) + log.Warn("cache context is expired, is highly likely to be misused for long-life tasks: %v", c) return nil } return c.Get(tp, key) @@ -146,7 +146,7 @@ func SetContextData(ctx context.Context, tp, key, value any) { if c.Expired() { // The warning means that the cache context is misused for long-life task, // it can be resolved with WithNoCacheContext(ctx). - log.Warn("cache context is expired, may be misused for long-life tasks: %v", c) + log.Warn("cache context is expired, is highly likely to be misused for long-life tasks: %v", c) return } c.Put(tp, key, value) @@ -159,7 +159,7 @@ func RemoveContextData(ctx context.Context, tp, key any) { if c.Expired() { // The warning means that the cache context is misused for long-life task, // it can be resolved with WithNoCacheContext(ctx). - log.Warn("cache context is expired, may be misused for long-life tasks: %v", c) + log.Warn("cache context is expired, is highly likely to be misused for long-life tasks: %v", c) return } c.Delete(tp, key) diff --git a/modules/cache/context_test.go b/modules/cache/context_test.go index 1ee3d2dd52..072c39440f 100644 --- a/modules/cache/context_test.go +++ b/modules/cache/context_test.go @@ -46,7 +46,7 @@ func TestWithCacheContext(t *testing.T) { timeNow = now }() timeNow = func() time.Time { - return now().Add(10 * time.Second) + return now().Add(5 * time.Minute) } v = GetContextData(ctx, field, "my_config1") assert.Nil(t, v)