From 4dcaa24758185d5c33aa09b4062b29cbd8babc6e Mon Sep 17 00:00:00 2001 From: Noah Hsu Date: Tue, 15 Nov 2022 14:38:23 +0800 Subject: [PATCH] fix: cache is modified while sorting (close #2340) --- internal/fs/list.go | 4 +++- internal/op/fs.go | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/fs/list.go b/internal/fs/list.go index 8a0ad0c3..f353ca6e 100644 --- a/internal/fs/list.go +++ b/internal/fs/list.go @@ -24,7 +24,7 @@ func list(ctx context.Context, path string, refresh ...bool) ([]model.Obj, error return nil, errors.WithMessage(err, "failed get storage") } } else { - objs, err = op.List(ctx, storage, actualPath, model.ListArgs{ + _objs, err := op.List(ctx, storage, actualPath, model.ListArgs{ ReqPath: path, }, refresh...) if err != nil { @@ -33,6 +33,8 @@ func list(ctx context.Context, path string, refresh ...bool) ([]model.Obj, error return nil, errors.WithMessage(err, "failed get objs") } } + objs = make([]model.Obj, len(_objs)) + copy(objs, _objs) } if objs == nil { objs = virtualFiles diff --git a/internal/op/fs.go b/internal/op/fs.go index 94207d8b..bdeb669e 100644 --- a/internal/op/fs.go +++ b/internal/op/fs.go @@ -60,8 +60,10 @@ func List(ctx context.Context, storage driver.Driver, path string, args model.Li } if !storage.Config().NoCache { if len(files) > 0 { + log.Debugf("set cache: %s => %+v", key, files) listCache.Set(key, files, cache.WithEx[[]model.Obj](time.Minute*time.Duration(storage.GetStorage().CacheExpiration))) } else { + log.Debugf("del cache: %s", key) listCache.Del(key) } }