Skip to content

Commit febbcd6

Browse files
ILoveScratch2KirCutej2rong4cn
authored
feat(cache): improve cache management (#1339)
* feat(cache): improve cache management * feat(disk-usage): add cache * feat(disk-usage): add refresh * fix(disk-usage): cache with ttl * feat(cache): implement KeyedCache and TypedCache for improved caching mechanism * fix(copy): update object retrieval to use Get instead of GetUnwrap * refactor(cache): simplify DirectoryCache structure and improve object management * fix(cache): correct cache entry initialization and key deletion logic in TypedCache * refactor(driver): remove GetObjInfo interface and simplify Link function logic https://github.com/OpenListTeam/OpenList/pull/888/files#r2430925783 * fix(link): optimize link retrieval and caching logic * refactor(cache): consolidate cache management and improve directory cache handling * fix(cache): add cache control based on storage configuration in List function * . * refactor: replace fmt.Sprintf with strconv for integer conversions * refactor(cache): enhance cache entry management with Expirable interface * fix(cache): improve link reference acquisition logic to handle expiration * refactor: replace OnlyLinkMFile with NoLinkSF in driver configurations and logic * refactor(link): enhance link caching logic with dynamic type keys based on IP and User-Agent * feat(drivers): add LinkCacheType to driver configurations for enhanced caching * refactor(cache): streamline directory object management in cache operations * refactor(cache): remove unnecessary 'dirty' field from CacheEntry structure * refactor(cache): replace 'dirty' field with bitwise flags * refactor(io): 调高SyncClosers.AcquireReference的优先级 * refactor(link): 优化链接获取逻辑,增加重 * refactor(link): 添加RequireReference字段以增强链接管理 * refactor(link): 移除MFile字段,改用RangeReader * refactor: 移除不必要的NoLinkSF字段 * refactor(cache): 修改目录缓存的脏标志定义和更新逻辑 * feat(cache): add expiration gc --------- Co-authored-by: KirCute <951206789@qq.com> Co-authored-by: KirCute <kircute@foxmail.com> Co-authored-by: j2rong4cn <j2rong@qq.com>
1 parent 549e601 commit febbcd6

File tree

56 files changed

+879
-508
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+879
-508
lines changed

drivers/115/meta.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ type Addition struct {
1515
}
1616

1717
var config = driver.Config{
18-
Name: "115 Cloud",
19-
DefaultRoot: "0",
20-
// OnlyProxy: true,
21-
// NoOverwriteUpload: true,
18+
Name: "115 Cloud",
19+
DefaultRoot: "0",
20+
LinkCacheType: 2,
2221
}
2322

2423
func init() {

drivers/115_open/driver.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -131,23 +131,6 @@ func (d *Open115) Link(ctx context.Context, file model.Obj, args model.LinkArgs)
131131
}, nil
132132
}
133133

134-
func (d *Open115) GetObjInfo(ctx context.Context, path string) (model.Obj, error) {
135-
if err := d.WaitLimit(ctx); err != nil {
136-
return nil, err
137-
}
138-
resp, err := d.client.GetFolderInfoByPath(ctx, path)
139-
if err != nil {
140-
return nil, err
141-
}
142-
return &Obj{
143-
Fid: resp.FileID,
144-
Fn: resp.FileName,
145-
Fc: resp.FileCategory,
146-
Sha1: resp.Sha1,
147-
Pc: resp.PickCode,
148-
}, nil
149-
}
150-
151134
func (d *Open115) MakeDir(ctx context.Context, parentDir model.Obj, dirName string) (model.Obj, error) {
152135
if err := d.WaitLimit(ctx); err != nil {
153136
return nil, err

drivers/115_open/meta.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ type Addition struct {
1717
}
1818

1919
var config = driver.Config{
20-
Name: "115 Open",
21-
DefaultRoot: "0",
20+
Name: "115 Open",
21+
DefaultRoot: "0",
22+
LinkCacheType: 2,
2223
}
2324

2425
func init() {

drivers/alias/driver.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (d *Alias) Get(ctx context.Context, path string) (model.Obj, error) {
130130
func (d *Alias) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]model.Obj, error) {
131131
path := dir.GetPath()
132132
if utils.PathEqual(path, "/") && !d.autoFlatten {
133-
return d.listRoot(ctx, args.WithStorageDetails && d.DetailsPassThrough), nil
133+
return d.listRoot(ctx, args.WithStorageDetails && d.DetailsPassThrough, args.Refresh), nil
134134
}
135135
root, sub := d.getRootAndPath(path)
136136
dsts, ok := d.pathMap[root]
@@ -211,9 +211,6 @@ func (d *Alias) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (
211211
if resultLink.ContentLength == 0 {
212212
resultLink.ContentLength = fi.GetSize()
213213
}
214-
if resultLink.MFile != nil {
215-
return &resultLink, nil
216-
}
217214
if d.DownloadConcurrency > 0 {
218215
resultLink.Concurrency = d.DownloadConcurrency
219216
}

drivers/alias/util.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
log "github.com/sirupsen/logrus"
1818
)
1919

20-
func (d *Alias) listRoot(ctx context.Context, withDetails bool) []model.Obj {
20+
func (d *Alias) listRoot(ctx context.Context, withDetails, refresh bool) []model.Obj {
2121
var objs []model.Obj
2222
var wg sync.WaitGroup
2323
for _, k := range d.rootOrder {
@@ -52,7 +52,7 @@ func (d *Alias) listRoot(ctx context.Context, withDetails bool) []model.Obj {
5252
defer wg.Done()
5353
c, cancel := context.WithTimeout(ctx, time.Second)
5454
defer cancel()
55-
details, e := op.GetStorageDetails(c, remoteDriver)
55+
details, e := op.GetStorageDetails(c, remoteDriver, refresh)
5656
if e != nil {
5757
if !errors.Is(e, errs.NotImplement) && !errors.Is(e, errs.StorageNotInit) {
5858
log.Errorf("failed get %s storage details: %+v", remoteDriver.GetStorage().MountPath, e)

drivers/baidu_photo/meta.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ type Addition struct {
1818
}
1919

2020
var config = driver.Config{
21-
Name: "BaiduPhoto",
22-
LocalSort: true,
21+
Name: "BaiduPhoto",
22+
LocalSort: true,
23+
LinkCacheType: 2,
2324
}
2425

2526
func init() {

drivers/chaoxing/driver.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"mime/multipart"
1111
"net/http"
1212
"net/url"
13+
"strconv"
1314
"strings"
1415
"time"
1516

@@ -239,7 +240,7 @@ func (d *ChaoXing) Put(ctx context.Context, dstDir model.Obj, file model.FileStr
239240
if err != nil {
240241
return err
241242
}
242-
err = writer.WriteField("puid", fmt.Sprintf("%d", resp.Msg.Puid))
243+
err = writer.WriteField("puid", strconv.Itoa(resp.Msg.Puid))
243244
if err != nil {
244245
fmt.Println("Error writing param2 to request body:", err)
245246
return err
@@ -260,7 +261,7 @@ func (d *ChaoXing) Put(ctx context.Context, dstDir model.Obj, file model.FileStr
260261
return err
261262
}
262263
req.Header.Set("Content-Type", writer.FormDataContentType())
263-
req.Header.Set("Content-Length", fmt.Sprintf("%d", body.Len()))
264+
req.Header.Set("Content-Length", strconv.Itoa(body.Len()))
264265
resps, err := http.DefaultClient.Do(req)
265266
if err != nil {
266267
return err

drivers/chaoxing/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ type UploadDoneParam struct {
258258
func fileToObj(f File) *model.Object {
259259
if len(f.Content.FolderName) > 0 {
260260
return &model.Object{
261-
ID: fmt.Sprintf("%d", f.ID),
261+
ID: strconv.Itoa(f.ID),
262262
Name: f.Content.FolderName,
263263
Size: 0,
264264
Modified: time.UnixMilli(f.Inserttime),

drivers/chaoxing/util.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"mime/multipart"
1111
"net/http"
12+
"strconv"
1213
"strings"
1314

1415
"github.com/OpenListTeam/OpenList/v4/drivers/base"
@@ -172,7 +173,7 @@ func (d *ChaoXing) Login() (string, error) {
172173
return "", err
173174
}
174175
req.Header.Set("Content-Type", writer.FormDataContentType())
175-
req.Header.Set("Content-Length", fmt.Sprintf("%d", body.Len()))
176+
req.Header.Set("Content-Length", strconv.Itoa(body.Len()))
176177
resp, err := http.DefaultClient.Do(req)
177178
if err != nil {
178179
return "", err

drivers/crypt/driver.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ func (d *Crypt) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (
317317
}
318318
return readSeeker, nil
319319
}),
320-
SyncClosers: utils.NewSyncClosers(remoteLink),
320+
SyncClosers: utils.NewSyncClosers(remoteLink),
321+
RequireReference: remoteLink.RequireReference,
321322
}, nil
322323
}
323324

0 commit comments

Comments
 (0)