SecureMapStorage as cache for EventCost

This commit is contained in:
DanB
2022-11-30 19:41:38 +01:00
parent 1897b88602
commit 751bcc7b2f
3 changed files with 77 additions and 5 deletions

View File

@@ -35,7 +35,7 @@ func NewBareEventCost() *EventCost {
Rates: make(ChargedRates),
Timings: make(ChargedTimings),
Charges: make([]*ChargingInterval, 0),
cache: utils.MapStorage{},
cache: utils.NewSecureMapStorage(),
}
}
@@ -160,12 +160,12 @@ type EventCost struct {
Rates ChargedRates
Timings ChargedTimings
cache utils.MapStorage
cache *utils.SecureMapStorage
}
func (ec *EventCost) initCache() {
if ec != nil {
ec.cache = utils.MapStorage{}
ec.cache = utils.NewSecureMapStorage()
}
}
@@ -952,7 +952,7 @@ func (ec *EventCost) Trim(atUsage time.Duration) (srplusEC *EventCost, err error
// FieldAsInterface func to implement DataProvider
func (ec *EventCost) FieldAsInterface(fldPath []string) (val interface{}, err error) {
if ec.cache == nil {
ec.cache = utils.MapStorage{} // fix gob deserialization
ec.initCache() // fix gob deserialization
}
if val, err = ec.cache.FieldAsInterface(fldPath); err != nil {
if err != utils.ErrNotFound { // item found in cache