lib/app/county-cache.go

30 lines
497 B
Go
Raw Normal View History

2021-01-27 22:39:23 +00:00
package app
import (
"sync"
"code.tnxs.net/taxnexus/lib/api/geo/geo_models"
)
var countyCache = countyCacheType{
obj: map[string]*geo_models.County{},
}
type countyCacheType struct {
sync.RWMutex
obj map[string]*geo_models.County
}
func (m *countyCacheType) get(key string) (*geo_models.County, bool) {
m.RLock()
defer m.RUnlock()
r, ok := m.obj[key]
return r, ok
}
func (m *countyCacheType) put(key string, obj *geo_models.County) {
m.Lock()
defer m.Unlock()
m.obj[key] = obj
}