diff --git a/cmd/haoquote/main.go b/cmd/haoquote/main.go index 9bf3b4e2..fd9b817e 100644 --- a/cmd/haoquote/main.go +++ b/cmd/haoquote/main.go @@ -78,7 +78,7 @@ func main() { rc := app.RedisInit() ctext := context.Background() - haoquote.Start(&ctext, rc, db) + haoquote.Run(&ctext, rc, db) return nil }, } diff --git a/haoquote/main.go b/haoquote/main.go index 89406212..f0c14e4f 100644 --- a/haoquote/main.go +++ b/haoquote/main.go @@ -9,10 +9,11 @@ import ( "github.com/spf13/viper" "github.com/yzimhao/trading_engine/haoquote/tradelog" "github.com/yzimhao/trading_engine/haoquote/www" + "github.com/yzimhao/trading_engine/utils/filecache" "xorm.io/xorm" ) -func Start(ctx *context.Context, rc *redis.Client, db *xorm.Engine) { +func Run(ctx *context.Context, rc *redis.Client, db *xorm.Engine) { wg := sync.WaitGroup{} wg.Add(1) init_symbols_quote() @@ -24,6 +25,7 @@ func Start(ctx *context.Context, rc *redis.Client, db *xorm.Engine) { func init_symbols_quote() { symbols := viper.GetStringMap("symbol") + filecache.NewStorage(viper.GetString("haoquote.storage_path"), 1) for k, attr := range symbols { symbol := strings.ToLower(k) diff --git a/haoquote/period/period_cache.go b/haoquote/period/period_cache.go index d45b259a..20cc0d08 100644 --- a/haoquote/period/period_cache.go +++ b/haoquote/period/period_cache.go @@ -21,7 +21,7 @@ func (c periodCachekey) Format(pt PeriodType, symbol string, st, et int64) strin } func newCache() *filecache.Storage { - return filecache.NewStorage(viper.GetString("haoquote.storage_path"), 10) + return filecache.NewStorage(viper.GetString("haoquote.storage_path"), 1) } func GetYesterdayClose(symbol string) (string, bool) { diff --git a/utils/filecache/storage.go b/utils/filecache/storage.go index 0f95bcc9..f0949bf5 100644 --- a/utils/filecache/storage.go +++ b/utils/filecache/storage.go @@ -15,7 +15,6 @@ type Storage struct { var obj *Storage func NewStorage(filename string, timeout time.Duration) *Storage { - if obj == nil { db, err := bolt.Open(filename, 0600, &bolt.Options{Timeout: timeout * time.Second}) if err != nil {