Skip to content

Commit e41dee1

Browse files
author
cyk
committed
refactor(link): 优化链接缓存逻辑,移除对 SyncClosers 的依赖,简化过期判断
1 parent 5a6bad9 commit e41dee1

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

internal/op/fs.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,9 @@ func Link(ctx context.Context, storage driver.Driver, path string, args model.Li
245245
}
246246
key := Key(storage, path)
247247
if ol, exists := Cache.linkCache.GetType(key, typeKey); exists {
248-
if ol.link.Expiration != nil ||
249-
ol.link.SyncClosers.AcquireReference() || !ol.link.RequireReference {
250-
return ol.link, ol.obj, nil
251-
}
248+
// 缓存命中:直接返回缓存的链接
249+
// 链接过期由 RefreshableRangeReader 在 HTTP 请求失败时检测并刷新
250+
return ol.link, ol.obj, nil
252251
}
253252

254253
fn := func() (*objWithLink, error) {
@@ -290,19 +289,18 @@ func Link(ctx context.Context, storage driver.Driver, path string, args model.Li
290289
if link.Expiration != nil {
291290
Cache.linkCache.SetTypeWithTTL(key, typeKey, ol, *link.Expiration)
292291
} else {
293-
Cache.linkCache.SetTypeWithExpirable(key, typeKey, ol, &link.SyncClosers)
292+
// 不使用 SyncClosers 作为过期判断,使用默认 TTL
293+
// 链接真正过期时由 RefreshableRangeReader 检测并刷新
294+
Cache.linkCache.SetType(key, typeKey, ol)
294295
}
295296
return ol, nil
296297
}
297-
for {
298-
ol, err, _ := linkG.Do(key+"/"+typeKey, fn)
299-
if err != nil {
300-
return nil, nil, err
301-
}
302-
if ol.link.SyncClosers.AcquireReference() || !ol.link.RequireReference {
303-
return ol.link, ol.obj, nil
304-
}
298+
// 直接执行获取链接,不再依赖 SyncClosers 引用计数
299+
ol, err, _ := linkG.Do(key+"/"+typeKey, fn)
300+
if err != nil {
301+
return nil, nil, err
305302
}
303+
return ol.link, ol.obj, nil
306304
}
307305

308306
// Other api

0 commit comments

Comments
 (0)