lib/app/accountingrule-cache.go

29 lines
658 B
Go
Raw 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 accountingRuleCache = accountingRuleCacheType{
obj: map[string]map[string]*ledger_models.AccountingRule{},
}
type accountingRuleCacheType struct {
sync.RWMutex
obj map[string]map[string]*ledger_models.AccountingRule
}
func (m *accountingRuleCacheType) get(accountID string) (map[string]*ledger_models.AccountingRule, bool) {
m.RLock()
defer m.RUnlock()
r, ok := m.obj[accountID]
return r, ok
}
func (m *accountingRuleCacheType) put(accountID string, rules map[string]*ledger_models.AccountingRule) {
m.Lock()
defer m.Unlock()
m.obj[accountID] = rules
}