Adding Cache to CGREventWithOpts

This commit is contained in:
DanB
2020-12-30 17:02:36 +01:00
parent 11d6d9be42
commit 56fbc84bea
2 changed files with 34 additions and 0 deletions

View File

@@ -43,5 +43,9 @@ type abstractBalance struct {
// debit implements the balanceOperator interface
func (ab *abstractBalance) debit(cgrEv *utils.CGREventWithOpts,
startTime time.Time, usage *decimal.Big) (ec *utils.EventCharges, err error) {
//var uF *utils.UsageFactor
if _, err = usageWithFactor(usage, ab.blnCfg, ab.fltrS, cgrEv); err != nil {
return
}
return
}

View File

@@ -150,6 +150,8 @@ type CGREvents struct {
type CGREventWithOpts struct {
Opts map[string]interface{}
*CGREvent
cache map[string]interface{}
}
// Clone return a copy of the CGREventWithOpts
@@ -170,6 +172,34 @@ func (ev *CGREventWithOpts) Clone() (clned *CGREventWithOpts) {
return
}
// CacheInit will initialize the cache if not already done
func (ev *CGREventWithOpts) CacheInit() {
if ev.cache == nil {
ev.cache = make(map[string]interface{})
}
}
// CacheClear will reset the cache
func (ev *CGREventWithOpts) CacheClear() {
ev.cache = make(map[string]interface{})
}
// CacheGet will return a key from the cache
func (ev *CGREventWithOpts) CacheGet(key string) (itm interface{}, has bool) {
itm, has = ev.cache[key]
return
}
// CacheSet will set data into the event's cache
func (ev *CGREventWithOpts) CacheSet(key string, val interface{}) {
ev.cache[key] = val
}
// CacheRemove will remove data from cache
func (ev *CGREventWithOpts) CacheRemove(key string) {
delete(ev.cache, key)
}
// EventWithFlags is used where flags are needed to mark processing
type EventWithFlags struct {
Flags []string