39 lines
848 B
Go
39 lines
848 B
Go
package app
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"code.tnxs.net/taxnexus/lib/api/ledger/ledger_models"
|
|
)
|
|
|
|
var glBalanceCache = glBalanceCacheType{
|
|
obj: map[string]map[string]*ledger_models.GlBalance{},
|
|
}
|
|
|
|
type glBalanceCacheType struct {
|
|
sync.RWMutex
|
|
obj map[string]map[string]*ledger_models.GlBalance
|
|
}
|
|
|
|
func (m *glBalanceCacheType) get(periodID, glAccountID string) (*ledger_models.GlBalance, bool) {
|
|
m.RLock()
|
|
defer m.RUnlock()
|
|
r, ok := m.obj[periodID][glAccountID]
|
|
return r, ok
|
|
}
|
|
|
|
func (m *glBalanceCacheType) put(periodID, glAccountID string, glBalance *ledger_models.GlBalance) {
|
|
m.init(periodID)
|
|
m.Lock()
|
|
defer m.Unlock()
|
|
m.obj[periodID][glAccountID] = glBalance
|
|
}
|
|
func (m *glBalanceCacheType) init(periodID string) {
|
|
m.RLock()
|
|
defer m.RUnlock()
|
|
_, ok := m.obj[periodID]
|
|
if !ok {
|
|
m.obj[periodID] = map[string]*ledger_models.GlBalance{}
|
|
}
|
|
}
|