lib/app/backend-cache.go

26 lines
427 B
Go
Raw Permalink Normal View History

2021-01-28 20:00:21 +00:00
package app
import "sync"
var backendCache = backendCacheType{
obj: map[string]*Backend{},
}
type backendCacheType struct {
sync.RWMutex
obj map[string]*Backend
}
func (m *backendCacheType) get(recordID string) (*Backend, bool) {
m.RLock()
defer m.RUnlock()
r, ok := m.obj[recordID]
return r, ok
}
func (m *backendCacheType) put(recordID string, itm *Backend) {
m.Lock()
defer m.Unlock()
m.obj[recordID] = itm
}