mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
make the first arg of WithCache as a key var
This commit is contained in:
parent
40c697275d
commit
2bbee6671a
|
@ -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()
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue
Block a user