mirror of
https://github.com/miguelmota/cointop
synced 2024-11-05 00:00:14 +00:00
Merge branch 'lyricnz-feature/duplicate-symbols-cache-fix'
This commit is contained in:
commit
ac9a4d44cc
@ -10,10 +10,24 @@ import (
|
||||
|
||||
// CacheKey returns cached value given key
|
||||
func (ct *Cointop) CacheKey(key string) string {
|
||||
log.Debug("CacheKey()")
|
||||
return strings.ToLower(fmt.Sprintf("%s_%s", ct.apiChoice, key))
|
||||
}
|
||||
|
||||
// CompositeCacheKey returns a CacheKey for a coin (or globaldata)
|
||||
func (ct *Cointop) CompositeCacheKey(symbol string, name string, convert string, chartRange string) string {
|
||||
keyname := symbol
|
||||
if name != "" {
|
||||
keyname += "-" + name
|
||||
}
|
||||
if convert != "" {
|
||||
keyname += "_" + convert
|
||||
}
|
||||
if chartRange != "" {
|
||||
keyname += "_" + strings.Replace(chartRange, " ", "", -1) // "All Time" contains space
|
||||
}
|
||||
return ct.CacheKey(keyname)
|
||||
}
|
||||
|
||||
// CacheAllCoinsSlugMap writes the coins map to the memory and disk cache
|
||||
func (ct *Cointop) CacheAllCoinsSlugMap() {
|
||||
log.Debug("CacheAllCoinsSlugMap()")
|
||||
|
@ -3,7 +3,6 @@ package cointop
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@ -127,7 +126,7 @@ func (ct *Cointop) ChartPoints(symbol string, name string) error {
|
||||
if keyname == "" {
|
||||
keyname = "globaldata"
|
||||
}
|
||||
cachekey := ct.CacheKey(fmt.Sprintf("%s_%s", keyname, strings.Replace(ct.State.selectedChartRange, " ", "", -1)))
|
||||
cachekey := ct.CompositeCacheKey(keyname, name, ct.State.currencyConversion, ct.State.selectedChartRange)
|
||||
|
||||
cached, found := ct.cache.Get(cachekey)
|
||||
if found {
|
||||
@ -219,7 +218,7 @@ func (ct *Cointop) PortfolioChart() error {
|
||||
}
|
||||
|
||||
var graphData []float64
|
||||
cachekey := strings.ToLower(fmt.Sprintf("%s_%s_%s", p.Symbol, convert, strings.Replace(selectedChartRange, " ", "", -1)))
|
||||
cachekey := ct.CompositeCacheKey(p.Symbol, p.Name, convert, selectedChartRange)
|
||||
cached, found := ct.cache.Get(cachekey)
|
||||
if found {
|
||||
// cache hit
|
||||
|
@ -445,7 +445,7 @@ func NewCointop(config *Config) (*Cointop, error) {
|
||||
})
|
||||
|
||||
var globaldata []float64
|
||||
chartcachekey := ct.CacheKey(fmt.Sprintf("%s_%s", "globaldata", strings.Replace(ct.State.selectedChartRange, " ", "", -1)))
|
||||
chartcachekey := ct.CompositeCacheKey("globaldata", "", "", ct.State.selectedChartRange)
|
||||
if ct.filecache != nil {
|
||||
ct.filecache.Get(chartcachekey, &globaldata)
|
||||
}
|
||||
|
@ -1,9 +1,6 @@
|
||||
package cointop
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@ -99,7 +96,7 @@ func (ct *Cointop) layout() error {
|
||||
ct.Views.Chart.SetBgColor(ct.colorscheme.GocuiBgColor(ct.Views.Chart.Name()))
|
||||
go func() {
|
||||
ct.UpdateChart()
|
||||
cachekey := strings.ToLower(fmt.Sprintf("%s_%s", "globaldata", strings.Replace(ct.State.selectedChartRange, " ", "", -1)))
|
||||
cachekey := ct.CompositeCacheKey("globaldata", "", "", ct.State.selectedChartRange)
|
||||
_, found := ct.cache.Get(cachekey)
|
||||
if found {
|
||||
ct.cache.Delete(cachekey)
|
||||
|
@ -102,7 +102,7 @@ func (ct *Cointop) UpdateMarketbar() error {
|
||||
|
||||
var market types.GlobalMarketData
|
||||
var err error
|
||||
cachekey := ct.CacheKey("market")
|
||||
cachekey := ct.CompositeCacheKey("market", "", ct.State.currencyConversion, "")
|
||||
cached, found := ct.cache.Get(cachekey)
|
||||
|
||||
if found {
|
||||
|
Loading…
Reference in New Issue
Block a user