lib/app/accountingruleset-cache.go

30 lines
686 B
Go
Raw Permalink Normal View History

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