Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
ae1ba453
Commit
ae1ba453
authored
Feb 06, 2026
by
yangjianbo
Browse files
perf(service): jitterTTL 改用 rand/v2 并移除锁
parent
c4182f8c
Changes
1
Show whitespace changes
Inline
Side-by-side
backend/internal/service/api_key_auth_cache_impl.go
View file @
ae1ba453
...
...
@@ -22,11 +22,6 @@ type apiKeyAuthCacheConfig struct {
singleflight
bool
}
var
(
// 认证缓存抖动直接使用 rand/v2 的顶层函数。
// rand/v2 顶层函数并发安全,避免全局互斥锁成为热点。
)
func
newAPIKeyAuthCacheConfig
(
cfg
*
config
.
Config
)
apiKeyAuthCacheConfig
{
if
cfg
==
nil
{
return
apiKeyAuthCacheConfig
{}
...
...
@@ -54,6 +49,8 @@ func (c apiKeyAuthCacheConfig) negativeEnabled() bool {
return
c
.
negativeTTL
>
0
}
// jitterTTL 为缓存 TTL 添加抖动,避免多个请求在同一时刻同时过期触发集中回源。
// 这里直接使用 rand/v2 的顶层函数:并发安全,无需全局互斥锁。
func
(
c
apiKeyAuthCacheConfig
)
jitterTTL
(
ttl
time
.
Duration
)
time
.
Duration
{
if
ttl
<=
0
{
return
ttl
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment