make the first arg of WithCache as a key var

This commit is contained in:
c9s 2020-10-20 12:18:29 +08:00
parent 40c697275d
commit 2bbee6671a
2 changed files with 3 additions and 3 deletions

View File

@ -10,9 +10,9 @@ import (
"github.com/pkg/errors"
)
func WithCache(file string, obj interface{}, do func() (interface{}, error)) error {
func WithCache(key string, obj interface{}, do func() (interface{}, error)) error {
cacheDir := CacheDir()
cacheFile := path.Join(cacheDir, file)
cacheFile := path.Join(cacheDir, key+ ".json")
if _, err := os.Stat(cacheFile); os.IsNotExist(err) {
data, err := do()

View File

@ -63,7 +63,7 @@ func (environ *Environment) Init(ctx context.Context) (err error) {
for _, session := range environ.sessions {
var markets types.MarketMap
err = WithCache(fmt.Sprintf("%s-markets.json", session.Exchange.Name()), &markets, func() (interface{}, error) {
err = WithCache(fmt.Sprintf("%s-markets", session.Exchange.Name()), &markets, func() (interface{}, error) {
return session.Exchange.QueryMarkets(ctx)
})
if err != nil {