From 289f88867bdf723f41d6c3915d1be1c651b30994 Mon Sep 17 00:00:00 2001 From: banbxio Date: Thu, 27 Mar 2025 23:43:36 +0800 Subject: [PATCH] refactor: Optimize download cache --- http/downloader.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/http/downloader.go b/http/downloader.go index 6e39ea5f..5f9a46cb 100644 --- a/http/downloader.go +++ b/http/downloader.go @@ -40,7 +40,6 @@ func NewDownloadTask(url, filename, pathname string, downloaderCache *cache.Cach Pathname: pathname, cache: downloaderCache, } - downloaderCache.Set(taskId.String(), downloadTask, cache.NoExpiration) return downloadTask } @@ -52,9 +51,6 @@ func (wc *WriteCounter) Write(p []byte) (int, error) { n := len(p) wc.task.savedSize += int64(n) wc.task.cache.Set(wc.task.TaskID.String(), wc.task, cache.NoExpiration) - if n == 0 { - wc.task.cache.Delete(wc.task.TaskID.String()) - } return n, nil } @@ -117,6 +113,7 @@ func downloadStatusHandler(downloaderCache *cache.Cache) handleFunc { } func downloadWithTask(fs afero.Fs, task *DownloadTask) error { + task.cache.Set(task.TaskID.String(), task, cache.NoExpiration) err := fs.MkdirAll(task.Pathname, files.PermDir) if err != nil { return err