lib/app/coordinate-cache.go

30 lines
577 B
Go
Raw Normal View History

2021-02-02 04:19:16 +00:00
package app
import (
"sync"
"code.tnxs.net/taxnexus/lib/api/geo/geo_models"
)
var coordinateCache = coordinateCacheType{
obj: map[string]*geo_models.CoordinateBasic{},
}
type coordinateCacheType struct {
sync.RWMutex
obj map[string]*geo_models.CoordinateBasic
}
func (m *coordinateCacheType) get(addrStr string) (*geo_models.CoordinateBasic, bool) {
m.RLock()
defer m.RUnlock()
r, ok := m.obj[addrStr]
return r, ok
}
func (m *coordinateCacheType) put(accountID string, coord *geo_models.CoordinateBasic) {
m.Lock()
defer m.Unlock()
m.obj[accountID] = coord
}