2 Star 7 Fork 10

王布衣/engine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
adapter.go 1.40 KB
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2023-10-17 13:38 . 优化代码
package cachel5
import (
"fmt"
"gitee.com/quant1x/engine/cache"
"gitee.com/quant1x/engine/factors"
"gitee.com/quant1x/gox/util/treemap"
"strings"
"sync"
)
const (
// 闪存路径
cache1dPrefix = "flash"
// 默认证券代码为上证指数
defaultSecurityCode = "sh000001"
)
// 返回文件路径, 指定关键字和日期
func getCache1DFilepath(key, date string) string {
cachePath, key, found := strings.Cut(key, "/")
if !found {
key = cachePath
cachePath = cache1dPrefix
}
cachePath = cache.GetRootPath() + "/" + cachePath
year := date[:4]
filename := fmt.Sprintf("%s/%s/%s.%s", cachePath, year, key, date)
return filename
}
// CacheAdapter 缓存适配器
//
// 一天一个特征组合缓存文件
type CacheAdapter interface {
// Name 名称
Name() string
// Checkout 加载指定日期的缓存
Checkout(date ...string)
// Merge 合并数据
Merge(p *treemap.Map)
// Factory 工厂
Factory(date, securityCode string) factors.Feature
}
var (
__loadMutex sync.Mutex
__mapLoader = map[string]CacheAdapter{}
)
func RegisterCacheLoader(key string, loader CacheAdapter) {
__loadMutex.Lock()
defer __loadMutex.Unlock()
__mapLoader[key] = loader
}
// SwitchDate 统一切换数据的缓存日期
func SwitchDate(date string) {
__loadMutex.Lock()
defer __loadMutex.Unlock()
for _, v := range __mapLoader {
v.Checkout(date)
}
}
func Get(key string) CacheAdapter {
return __mapLoader[key]
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/quant1x/engine.git
git@gitee.com:quant1x/engine.git
quant1x
engine
engine
v0.7.4

搜索帮助