fix: cache is modified while sorting (close #2340)

pull/2344/head
Noah Hsu 2022-11-15 14:38:23 +08:00
parent 3fbdf6f022
commit 4dcaa24758
2 changed files with 5 additions and 1 deletions

View File

@ -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

View File

@ -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)
}
}