fix issue 4311

This commit is contained in:
AllenX2018
2020-11-17 20:53:33 +08:00
parent 05d8e293f7
commit 6225f0c1e9
8 changed files with 136 additions and 31 deletions

24
client/cache/file.go vendored
View File

@@ -28,6 +28,7 @@ import (
"path/filepath"
"reflect"
"strconv"
"strings"
"time"
"github.com/pkg/errors"
@@ -144,17 +145,22 @@ func (fc *FileCache) Get(ctx context.Context, key string) (interface{}, error) {
// GetMulti gets values from file cache.
// if nonexistent or expired return an empty string.
func (fc *FileCache) GetMulti(ctx context.Context, keys []string) ([]interface{}, error) {
var rc []interface{}
for _, key := range keys {
val, err := fc.Get(context.Background(), key)
if err != nil {
rc = append(rc, err)
} else {
rc = append(rc, val)
}
rc := make([]interface{}, len(keys))
keysErr := make([]string, 0)
for i, ki := range keys {
val, err := fc.Get(context.Background(), ki)
if err != nil {
keysErr = append(keysErr, fmt.Sprintf("key [%s] error: %s", ki, err.Error()))
continue
}
rc[i] = val
}
return rc, nil
if len(keysErr) == 0 {
return rc, nil
}
return rc, errors.New(strings.Join(keysErr, "; "))
}
// Put value into file cache.