diff --git a/cache2go/cache.go b/cache2go/cache.go
index 7a0a473ae..a3154a0cd 100644
--- a/cache2go/cache.go
+++ b/cache2go/cache.go
@@ -35,31 +35,31 @@ func init() {
}
}
-func CacheBeginTransaction() {
+func BeginTransaction() {
transactionMux.Lock()
transactionLock = true
transactionON = true
}
-func CacheRollbackTransaction() {
+func RollbackTransaction() {
transactionBuffer = nil
transactionLock = false
transactionON = false
transactionMux.Unlock()
}
-func CacheCommitTransaction() {
+func CommitTransaction() {
transactionON = false
// apply all transactioned items
mux.Lock()
for _, item := range transactionBuffer {
switch item.kind {
case KIND_REM:
- CacheRemKey(item.key)
+ RemKey(item.key)
case KIND_PRF:
- CacheRemPrefixKey(item.key)
+ RemPrefixKey(item.key)
case KIND_ADD:
- CacheSet(item.key, item.value)
+ Set(item.key, item.value)
}
}
mux.Unlock()
@@ -69,7 +69,7 @@ func CacheCommitTransaction() {
}
// The function to be used to cache a key/value pair when expiration is not needed
-func CacheSet(key string, value interface{}) {
+func Set(key string, value interface{}) {
if !transactionLock {
mux.Lock()
defer mux.Unlock()
@@ -83,13 +83,13 @@ func CacheSet(key string, value interface{}) {
}
// The function to extract a value for a key that never expire
-func CacheGet(key string) (interface{}, bool) {
+func Get(key string) (interface{}, bool) {
mux.RLock()
defer mux.RUnlock()
return cache.Get(key)
}
-func CacheRemKey(key string) {
+func RemKey(key string) {
if !transactionLock {
mux.Lock()
defer mux.Unlock()
@@ -101,7 +101,7 @@ func CacheRemKey(key string) {
}
}
-func CacheRemPrefixKey(prefix string) {
+func RemPrefixKey(prefix string) {
if !transactionLock {
mux.Lock()
defer mux.Unlock()
@@ -114,7 +114,7 @@ func CacheRemPrefixKey(prefix string) {
}
// Delete all keys from cache
-func CacheFlush() {
+func Flush() {
mux.Lock()
defer mux.Unlock()
if DOUBLE_CACHE {
@@ -124,19 +124,19 @@ func CacheFlush() {
}
}
-func CacheCountEntries(prefix string) (result int) {
+func CountEntries(prefix string) (result int) {
mux.RLock()
defer mux.RUnlock()
return cache.CountEntriesForPrefix(prefix)
}
-func CacheGetAllEntries(prefix string) (map[string]interface{}, error) {
+func GetAllEntries(prefix string) (map[string]interface{}, error) {
mux.RLock()
defer mux.RUnlock()
return cache.GetAllForPrefix(prefix)
}
-func CacheGetEntriesKeys(prefix string) (keys []string) {
+func GetEntriesKeys(prefix string) (keys []string) {
mux.RLock()
defer mux.RUnlock()
return cache.GetKeysForPrefix(prefix)
diff --git a/cache2go/cache_test.go b/cache2go/cache_test.go
index 1726a144b..3f0ac59cf 100644
--- a/cache2go/cache_test.go
+++ b/cache2go/cache_test.go
@@ -3,95 +3,95 @@ package cache2go
import "testing"
func TestRemKey(t *testing.T) {
- CacheSet("t11_mm", "test")
- if t1, ok := CacheGet("t11_mm"); !ok || t1 != "test" {
+ Set("t11_mm", "test")
+ if t1, ok := Get("t11_mm"); !ok || t1 != "test" {
t.Error("Error setting cache: ", ok, t1)
}
- CacheRemKey("t11_mm")
- if t1, ok := CacheGet("t11_mm"); ok || t1 == "test" {
+ RemKey("t11_mm")
+ if t1, ok := Get("t11_mm"); ok || t1 == "test" {
t.Error("Error removing cached key")
}
}
func TestTransaction(t *testing.T) {
- CacheBeginTransaction()
- CacheSet("t11_mm", "test")
- if t1, ok := CacheGet("t11_mm"); ok || t1 == "test" {
+ BeginTransaction()
+ Set("t11_mm", "test")
+ if t1, ok := Get("t11_mm"); ok || t1 == "test" {
t.Error("Error in transaction cache")
}
- CacheSet("t12_mm", "test")
- CacheRemKey("t11_mm")
- CacheCommitTransaction()
- if t1, ok := CacheGet("t12_mm"); !ok || t1 != "test" {
+ Set("t12_mm", "test")
+ RemKey("t11_mm")
+ CommitTransaction()
+ if t1, ok := Get("t12_mm"); !ok || t1 != "test" {
t.Error("Error commiting transaction")
}
- if t1, ok := CacheGet("t11_mm"); ok || t1 == "test" {
+ if t1, ok := Get("t11_mm"); ok || t1 == "test" {
t.Error("Error in transaction cache")
}
}
func TestTransactionRem(t *testing.T) {
- CacheBeginTransaction()
- CacheSet("t21_mm", "test")
- CacheSet("t21_nn", "test")
- CacheRemPrefixKey("t21_")
- CacheCommitTransaction()
- if t1, ok := CacheGet("t21_mm"); ok || t1 == "test" {
+ BeginTransaction()
+ Set("t21_mm", "test")
+ Set("t21_nn", "test")
+ RemPrefixKey("t21_")
+ CommitTransaction()
+ if t1, ok := Get("t21_mm"); ok || t1 == "test" {
t.Error("Error commiting transaction")
}
- if t1, ok := CacheGet("t21_nn"); ok || t1 == "test" {
+ if t1, ok := Get("t21_nn"); ok || t1 == "test" {
t.Error("Error in transaction cache")
}
}
func TestTransactionRollback(t *testing.T) {
- CacheBeginTransaction()
- CacheSet("t31_mm", "test")
- if t1, ok := CacheGet("t31_mm"); ok || t1 == "test" {
+ BeginTransaction()
+ Set("t31_mm", "test")
+ if t1, ok := Get("t31_mm"); ok || t1 == "test" {
t.Error("Error in transaction cache")
}
- CacheSet("t32_mm", "test")
- CacheRollbackTransaction()
- if t1, ok := CacheGet("t32_mm"); ok || t1 == "test" {
+ Set("t32_mm", "test")
+ RollbackTransaction()
+ if t1, ok := Get("t32_mm"); ok || t1 == "test" {
t.Error("Error commiting transaction")
}
- if t1, ok := CacheGet("t31_mm"); ok || t1 == "test" {
+ if t1, ok := Get("t31_mm"); ok || t1 == "test" {
t.Error("Error in transaction cache")
}
}
func TestTransactionRemBefore(t *testing.T) {
- CacheBeginTransaction()
- CacheRemPrefixKey("t41_")
- CacheSet("t41_mm", "test")
- CacheSet("t41_nn", "test")
- CacheCommitTransaction()
- if t1, ok := CacheGet("t41_mm"); !ok || t1 != "test" {
+ BeginTransaction()
+ RemPrefixKey("t41_")
+ Set("t41_mm", "test")
+ Set("t41_nn", "test")
+ CommitTransaction()
+ if t1, ok := Get("t41_mm"); !ok || t1 != "test" {
t.Error("Error commiting transaction")
}
- if t1, ok := CacheGet("t41_nn"); !ok || t1 != "test" {
+ if t1, ok := Get("t41_nn"); !ok || t1 != "test" {
t.Error("Error in transaction cache")
}
}
-func TestCacheRemPrefixKey(t *testing.T) {
- CacheSet("xxx_t1", "test")
- CacheSet("yyy_t1", "test")
- CacheRemPrefixKey("xxx_")
- _, okX := CacheGet("xxx_t1")
- _, okY := CacheGet("yyy_t1")
+func TestRemPrefixKey(t *testing.T) {
+ Set("xxx_t1", "test")
+ Set("yyy_t1", "test")
+ RemPrefixKey("xxx_")
+ _, okX := Get("xxx_t1")
+ _, okY := Get("yyy_t1")
if okX || !okY {
t.Error("Error removing prefix: ", okX, okY)
}
}
/*func TestCount(t *testing.T) {
- CacheSet("dst_A1", "1")
- CacheSet("dst_A2", "2")
- CacheSet("rpf_A3", "3")
- CacheSet("dst_A4", "4")
- CacheSet("dst_A5", "5")
- if CacheCountEntries("dst_") != 4 {
- t.Error("Error countiong entries: ", CacheCountEntries("dst_"))
+ Set("dst_A1", "1")
+ Set("dst_A2", "2")
+ Set("rpf_A3", "3")
+ Set("dst_A4", "4")
+ Set("dst_A5", "5")
+ if CountEntries("dst_") != 4 {
+ t.Error("Error countiong entries: ", CountEntries("dst_"))
}
}*/
diff --git a/engine/account.go b/engine/account.go
index 4be6ccf4e..6e433d205 100644
--- a/engine/account.go
+++ b/engine/account.go
@@ -24,6 +24,7 @@ import (
"fmt"
"time"
+ "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/structmatcher"
"github.com/cgrates/cgrates/utils"
@@ -54,7 +55,7 @@ func (ub *Account) getCreditForPrefix(cd *CallDescriptor) (duration time.Duratio
for _, cb := range creditBalances {
if len(cb.SharedGroups) > 0 {
for sg := range cb.SharedGroups {
- if sharedGroup, _ := ratingStorage.GetSharedGroup(sg); sharedGroup != nil {
+ if sharedGroup, _ := ratingStorage.GetSharedGroup(sg, false); sharedGroup != nil {
sgb := sharedGroup.GetBalances(cd.Destination, cd.Category, cd.Direction, utils.MONETARY, ub)
sgb = sharedGroup.SortBalancesByStrategy(cb, sgb)
extendedCreditBalances = append(extendedCreditBalances, sgb...)
@@ -68,7 +69,7 @@ func (ub *Account) getCreditForPrefix(cd *CallDescriptor) (duration time.Duratio
for _, mb := range unitBalances {
if len(mb.SharedGroups) > 0 {
for sg := range mb.SharedGroups {
- if sharedGroup, _ := ratingStorage.GetSharedGroup(sg); sharedGroup != nil {
+ if sharedGroup, _ := ratingStorage.GetSharedGroup(sg, false); sharedGroup != nil {
sgb := sharedGroup.GetBalances(cd.Destination, cd.Category, cd.Direction, cd.TOR, ub)
sgb = sharedGroup.SortBalancesByStrategy(mb, sgb)
extendedMinuteBalances = append(extendedMinuteBalances, sgb...)
@@ -136,7 +137,7 @@ func (acc *Account) setBalanceAction(a *Action) error {
_, err := Guardian.Guard(func() (interface{}, error) {
for sgID := range balance.SharedGroups {
// add shared group member
- sg, err := ratingStorage.GetSharedGroup(sgID)
+ sg, err := ratingStorage.GetSharedGroup(sgID, false)
if err != nil || sg == nil {
//than is problem
utils.Logger.Warning(fmt.Sprintf("Could not get shared group: %v", sgID))
@@ -147,7 +148,7 @@ func (acc *Account) setBalanceAction(a *Action) error {
sg.MemberIds = make(utils.StringMap)
}
sg.MemberIds[acc.ID] = true
- ratingStorage.SetSharedGroup(sg)
+ ratingStorage.SetSharedGroup(sg, true)
}
}
}
@@ -224,7 +225,7 @@ func (ub *Account) debitBalanceAction(a *Action, reset bool) error {
_, err := Guardian.Guard(func() (interface{}, error) {
for sgId := range bClone.SharedGroups {
// add shared group member
- sg, err := ratingStorage.GetSharedGroup(sgId)
+ sg, err := ratingStorage.GetSharedGroup(sgId, false)
if err != nil || sg == nil {
//than is problem
utils.Logger.Warning(fmt.Sprintf("Could not get shared group: %v", sgId))
@@ -235,7 +236,7 @@ func (ub *Account) debitBalanceAction(a *Action, reset bool) error {
sg.MemberIds = make(utils.StringMap)
}
sg.MemberIds[ub.ID] = true
- ratingStorage.SetSharedGroup(sg)
+ ratingStorage.SetSharedGroup(sg, true)
}
}
}
@@ -304,7 +305,7 @@ func (ub *Account) getBalancesForPrefix(prefix, category, direction, tor string,
if len(b.DestinationIDs) > 0 && b.DestinationIDs[utils.ANY] == false {
for _, p := range utils.SplitPrefix(prefix, MIN_PREFIX_MATCH) {
- if x, ok := CacheGet(utils.DESTINATION_PREFIX + p); ok {
+ if x, ok := cache2go.Get(utils.DESTINATION_PREFIX + p); ok {
destIds := x.(map[string]struct{})
foundResult := false
allInclude := true // wheter it is excluded or included
@@ -355,7 +356,7 @@ func (account *Account) getAlldBalancesForPrefix(destination, category, directio
for _, b := range balances {
if len(b.SharedGroups) > 0 {
for sgId := range b.SharedGroups {
- sharedGroup, err := ratingStorage.GetSharedGroup(sgId)
+ sharedGroup, err := ratingStorage.GetSharedGroup(sgId, false)
if err != nil || sharedGroup == nil {
utils.Logger.Warning(fmt.Sprintf("Could not get shared group: %v", sgId))
continue
@@ -774,7 +775,7 @@ func (account *Account) GetUniqueSharedGroupMembers(cd *CallDescriptor) (utils.S
}
memberIds := make(utils.StringMap)
for _, sgID := range sharedGroupIds {
- sharedGroup, err := ratingStorage.GetSharedGroup(sgID)
+ sharedGroup, err := ratingStorage.GetSharedGroup(sgID, false)
if err != nil {
utils.Logger.Warning(fmt.Sprintf("Could not get shared group: %v", sgID))
return nil, err
diff --git a/engine/account_test.go b/engine/account_test.go
index 21a6b07ea..d1ff3903a 100644
--- a/engine/account_test.go
+++ b/engine/account_test.go
@@ -1245,8 +1245,7 @@ func TestDebitShared(t *testing.T) {
sg := &SharedGroup{Id: "SG_TEST", MemberIds: utils.NewStringMap(rif.ID, groupie.ID), AccountParameters: map[string]*SharingParameters{"*any": &SharingParameters{Strategy: STRATEGY_MINE_RANDOM}}}
accountingStorage.SetAccount(groupie)
- ratingStorage.SetSharedGroup(sg)
- CacheSet(utils.SHARED_GROUP_PREFIX+"SG_TEST", sg)
+ ratingStorage.SetSharedGroup(sg, true)
cc, err := rif.debitCreditBalance(cd, false, false, true)
if err != nil {
t.Error("Error debiting balance: ", err)
@@ -1315,8 +1314,7 @@ func TestMaxDurationShared(t *testing.T) {
sg := &SharedGroup{Id: "SG_TEST", MemberIds: utils.NewStringMap(rif.ID, groupie.ID), AccountParameters: map[string]*SharingParameters{"*any": &SharingParameters{Strategy: STRATEGY_MINE_RANDOM}}}
accountingStorage.SetAccount(groupie)
- ratingStorage.SetSharedGroup(sg)
- CacheSet(utils.SHARED_GROUP_PREFIX+"SG_TEST", sg)
+ ratingStorage.SetSharedGroup(sg, true)
duration, err := cd.getMaxSessionDuration(rif)
if err != nil {
t.Error("Error getting max session duration from shared group: ", err)
diff --git a/engine/action.go b/engine/action.go
index ad7c20751..a5629a2b8 100644
--- a/engine/action.go
+++ b/engine/action.go
@@ -517,12 +517,17 @@ func setddestinations(ub *Account, sq *StatsQueueTriggered, a *Action, acs Actio
prefixes[i] = p
i++
}
+ newDest := &Destination{Id: ddcDestId, Prefixes: prefixes}
+ oldDest, err := ratingStorage.GetDestination(ddcDestId)
// update destid in storage
- ratingStorage.SetDestination(&Destination{Id: ddcDestId, Prefixes: prefixes})
- // remove existing from cache
- CleanStalePrefixes([]string{ddcDestId})
- // update new values from redis
- ratingStorage.CacheRatingPrefixValues("SetDestinationAction", map[string][]string{utils.DESTINATION_PREFIX: []string{utils.DESTINATION_PREFIX + ddcDestId}})
+ ratingStorage.SetDestination(newDest)
+
+ if err == nil && oldDest != nil {
+ err = ratingStorage.UpdateReverseDestination(oldDest, newDest)
+ if err != nil {
+ return err
+ }
+ }
} else {
return utils.ErrNotFound
}
@@ -559,20 +564,20 @@ func removeAccountAction(ub *Account, sq *StatsQueueTriggered, a *Action, acs Ac
utils.Logger.Err(fmt.Sprintf("Could not get action plans: %s: %v", accID, err))
return 0, err
}
- var dirtyAps []string
+ //var dirtyAps []string
for key, ap := range allAPs {
if _, exists := ap.AccountIDs[accID]; !exists {
// save action plan
delete(ap.AccountIDs, key)
- ratingStorage.SetActionPlan(key, ap, true)
- dirtyAps = append(dirtyAps, utils.ACTION_PLAN_PREFIX+key)
+ ratingStorage.SetActionPlan(key, ap, true, true)
+ //dirtyAps = append(dirtyAps, utils.ACTION_PLAN_PREFIX+key)
}
}
- if len(dirtyAps) > 0 {
+ /*if len(dirtyAps) > 0 {
// cache
ratingStorage.CacheRatingPrefixValues("RemoveAccountAction", map[string][]string{
utils.ACTION_PLAN_PREFIX: dirtyAps})
- }
+ }*/
return 0, nil
}, 0, utils.ACTION_PLAN_PREFIX)
diff --git a/engine/action_plan.go b/engine/action_plan.go
index c478c9953..cf6b82219 100644
--- a/engine/action_plan.go
+++ b/engine/action_plan.go
@@ -268,7 +268,7 @@ func (at *ActionTiming) GetActionPlanID() string {
func (at *ActionTiming) getActions() (as []*Action, err error) {
if at.actions == nil {
- at.actions, err = ratingStorage.GetActions(at.ActionsID)
+ at.actions, err = ratingStorage.GetActions(at.ActionsID, false)
}
at.actions.Sort()
return at.actions, err
diff --git a/engine/action_trigger.go b/engine/action_trigger.go
index dea6a54d3..4ff7a94ac 100644
--- a/engine/action_trigger.go
+++ b/engine/action_trigger.go
@@ -57,7 +57,7 @@ func (at *ActionTrigger) Execute(ub *Account, sq *StatsQueueTriggered) (err erro
}
// does NOT need to Lock() because it is triggered from a method that took the Lock
var aac Actions
- aac, err = ratingStorage.GetActions(at.ActionsID)
+ aac, err = ratingStorage.GetActions(at.ActionsID, false)
if err != nil {
utils.Logger.Err(fmt.Sprintf("Failed to get actions: %v", err))
return
diff --git a/engine/actions_test.go b/engine/actions_test.go
index 4a9d8daef..b6f13a09e 100644
--- a/engine/actions_test.go
+++ b/engine/actions_test.go
@@ -26,6 +26,7 @@ import (
"testing"
"time"
+ "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
)
@@ -1286,16 +1287,15 @@ func TestActionSetDDestination(t *testing.T) {
acc := &Account{BalanceMap: map[string]Balances{utils.MONETARY: Balances{&Balance{DestinationIDs: utils.NewStringMap("*ddc_test")}}}}
origD := &Destination{Id: "*ddc_test", Prefixes: []string{"111", "222"}}
ratingStorage.SetDestination(origD)
- ratingStorage.CacheRatingPrefixValues("", map[string][]string{utils.DESTINATION_PREFIX: []string{utils.DESTINATION_PREFIX + "*ddc_test"}})
// check redis and cache
if d, err := ratingStorage.GetDestination("*ddc_test"); err != nil || !reflect.DeepEqual(d, origD) {
t.Error("Error storing destination: ", d, err)
}
- x1, found := CacheGet(utils.DESTINATION_PREFIX + "111")
+ x1, found := cache2go.Get(utils.DESTINATION_PREFIX + "111")
if _, ok := x1.(map[string]struct{})["*ddc_test"]; !found || !ok {
t.Error("Error cacheing destination: ", x1)
}
- x1, found = CacheGet(utils.DESTINATION_PREFIX + "222")
+ x1, found = cache2go.Get(utils.DESTINATION_PREFIX + "222")
if _, ok := x1.(map[string]struct{})["*ddc_test"]; !found || !ok {
t.Error("Error cacheing destination: ", x1)
}
@@ -1308,19 +1308,19 @@ func TestActionSetDDestination(t *testing.T) {
t.Error("Error storing destination: ", d, err)
}
var ok bool
- x1, ok = CacheGet(utils.DESTINATION_PREFIX + "111")
+ x1, ok = cache2go.Get(utils.DESTINATION_PREFIX + "111")
if ok {
t.Error("Error cacheing destination: ", x1)
}
- x1, ok = CacheGet(utils.DESTINATION_PREFIX + "222")
+ x1, ok = cache2go.Get(utils.DESTINATION_PREFIX + "222")
if ok {
t.Error("Error cacheing destination: ", x1)
}
- x1, found = CacheGet(utils.DESTINATION_PREFIX + "333")
+ x1, found = cache2go.Get(utils.DESTINATION_PREFIX + "333")
if _, ok := x1.(map[string]struct{})["*ddc_test"]; !found || !ok {
t.Error("Error cacheing destination: ", x1)
}
- x1, found = CacheGet(utils.DESTINATION_PREFIX + "444")
+ x1, found = cache2go.Get(utils.DESTINATION_PREFIX + "444")
if _, ok := x1.(map[string]struct{})["*ddc_test"]; !found || !ok {
t.Error("Error cacheing destination: ", x1)
}
diff --git a/engine/aliases.go b/engine/aliases.go
index 0b23fb224..c47c0aadc 100644
--- a/engine/aliases.go
+++ b/engine/aliases.go
@@ -6,6 +6,7 @@ import (
"strings"
"sync"
+ "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
"github.com/cgrates/rpcclient"
)
@@ -114,29 +115,6 @@ func (al *Alias) SetId(id string) error {
return nil
}
-func (al *Alias) SetReverseCache() {
- for _, value := range al.Values {
- for target, pairs := range value.Pairs {
- for _, alias := range pairs {
- rKey := strings.Join([]string{utils.REVERSE_ALIASES_PREFIX, alias, target, al.Context}, "")
- CachePush(rKey, utils.ConcatenatedKey(al.GetId(), value.DestinationId))
- }
- }
- }
-}
-
-func (al *Alias) RemoveReverseCache() {
- for _, value := range al.Values {
- tmpKey := utils.ConcatenatedKey(al.GetId(), value.DestinationId)
- for target, pairs := range value.Pairs {
- for _, alias := range pairs {
- rKey := utils.REVERSE_ALIASES_PREFIX + alias + target + al.Context
- CachePop(rKey, tmpKey)
- }
- }
- }
-}
-
type AttrMatchingAlias struct {
Destination string
Direction string
@@ -188,11 +166,11 @@ func (am *AliasHandler) SetAlias(attr *AttrAddAlias, reply *string) error {
var oldAlias *Alias
if !attr.Overwrite { // get previous value
- oldAlias, _ = am.accountingDb.GetAlias(attr.Alias.GetId())
+ oldAlias, _ = am.accountingDb.GetAlias(attr.Alias.GetId(), false)
}
if attr.Overwrite || oldAlias == nil {
- if err := am.accountingDb.SetAlias(attr.Alias); err != nil {
+ if err := am.accountingDb.SetAlias(attr.Alias, false); err != nil {
*reply = err.Error()
return err
}
@@ -221,17 +199,17 @@ func (am *AliasHandler) SetAlias(attr *AttrAddAlias, reply *string) error {
oldAlias.Values = append(oldAlias.Values, value)
}
}
- if err := am.accountingDb.SetAlias(oldAlias); err != nil {
+ if err := am.accountingDb.SetAlias(oldAlias, true); err != nil {
*reply = err.Error()
return err
}
+ // FIXME!!!!
+ err = am.accountingDb.UpdateReverseAlias(oldAlias, oldAlias)
+ if err != nil {
+ return err
+ }
}
- //add to cache
- aliasesChanged := []string{utils.ALIASES_PREFIX + attr.Alias.GetId()}
- if err := am.accountingDb.CacheAccountingPrefixValues("SetAliasAPI", map[string][]string{utils.ALIASES_PREFIX: aliasesChanged}); err != nil {
- return utils.NewErrServerError(err)
- }
*reply = utils.OK
return nil
}
@@ -251,7 +229,7 @@ func (am *AliasHandler) RemoveReverseAlias(attr *AttrReverseAlias, reply *string
am.mu.Lock()
defer am.mu.Unlock()
rKey := utils.REVERSE_ALIASES_PREFIX + attr.Alias + attr.Target + attr.Context
- if x, ok := CacheGet(rKey); ok {
+ if x, ok := cache2go.Get(rKey); ok {
existingKeys := x.(map[interface{}]struct{})
for iKey := range existingKeys {
key := iKey.(string)
@@ -288,7 +266,7 @@ func (am *AliasHandler) GetReverseAlias(attr *AttrReverseAlias, result *map[stri
defer am.mu.Unlock()
aliases := make(map[string][]*Alias)
rKey := utils.REVERSE_ALIASES_PREFIX + attr.Alias + attr.Target + attr.Context
- if x, ok := CacheGet(rKey); ok {
+ if x, ok := cache2go.Get(rKey); ok {
existingKeys := x.(map[string]struct{})
for key := range existingKeys {
// get destination id
@@ -339,7 +317,7 @@ func (am *AliasHandler) GetMatchingAlias(attr *AttrMatchingAlias, result *string
}
// check destination ids
for _, p := range utils.SplitPrefix(attr.Destination, MIN_PREFIX_MATCH) {
- if x, ok := CacheGet(utils.DESTINATION_PREFIX + p); ok {
+ if x, ok := cache2go.Get(utils.DESTINATION_PREFIX + p); ok {
destIds := x.(map[string]struct{})
for _, value := range values {
for dId := range destIds {
@@ -419,7 +397,7 @@ func LoadAlias(attr *AttrMatchingAlias, in interface{}, extraFields string) erro
if rightPairs == nil {
// check destination ids
for _, p := range utils.SplitPrefix(attr.Destination, MIN_PREFIX_MATCH) {
- if x, ok := CacheGet(utils.DESTINATION_PREFIX + p); ok {
+ if x, ok := cache2go.Get(utils.DESTINATION_PREFIX + p); ok {
destIds := x.(map[string]struct{})
for _, value := range values {
for dId := range destIds {
diff --git a/engine/aliases_test.go b/engine/aliases_test.go
index 10825c8ec..0eb8c5fce 100644
--- a/engine/aliases_test.go
+++ b/engine/aliases_test.go
@@ -3,6 +3,7 @@ package engine
import (
"testing"
+ "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
)
@@ -207,31 +208,31 @@ func TestAliasesLoadAlias(t *testing.T) {
func TestAliasesCache(t *testing.T) {
key := "*out:cgrates.org:call:remo:remo:*rating"
- a, found := CacheGet(utils.ALIASES_PREFIX + key)
+ a, found := cache2go.Get(utils.ALIASES_PREFIX + key)
if !found || a == nil {
- //log.Printf("Test: %+v", CacheGetEntriesKeys(utils.REVERSE_ALIASES_PREFIX))
+ //log.Printf("Test: %+v", cache2go.GetEntriesKeys(utils.REVERSE_ALIASES_PREFIX))
t.Error("Error getting alias from cache: ", err, a)
}
rKey1 := "minuAccount*rating"
- ra1, found := CacheGet(utils.REVERSE_ALIASES_PREFIX + rKey1)
+ ra1, found := cache2go.Get(utils.REVERSE_ALIASES_PREFIX + rKey1)
if !found || len(ra1.(map[string]struct{})) != 2 {
t.Error("Error getting reverse alias 1: ", ra1)
}
rKey2 := "minuSubject*rating"
- ra2, found := CacheGet(utils.REVERSE_ALIASES_PREFIX + rKey2)
+ ra2, found := cache2go.Get(utils.REVERSE_ALIASES_PREFIX + rKey2)
if !found || len(ra2.(map[string]struct{})) != 2 {
t.Error("Error getting reverse alias 2: ", ra2)
}
accountingStorage.RemoveAlias(key)
- a, found = CacheGet(utils.ALIASES_PREFIX + key)
+ a, found = cache2go.Get(utils.ALIASES_PREFIX + key)
if found {
t.Error("Error getting alias from cache: ", found)
}
- ra1, found = CacheGet(utils.REVERSE_ALIASES_PREFIX + rKey1)
+ ra1, found = cache2go.Get(utils.REVERSE_ALIASES_PREFIX + rKey1)
if !found || len(ra1.(map[string]struct{})) != 1 {
t.Error("Error getting reverse alias 1: ", ra1)
}
- ra2, found = CacheGet(utils.REVERSE_ALIASES_PREFIX + rKey2)
+ ra2, found = cache2go.Get(utils.REVERSE_ALIASES_PREFIX + rKey2)
if !found || len(ra2.(map[string]struct{})) != 1 {
t.Error("Error getting reverse alias 2: ", ra2)
}
diff --git a/engine/balances.go b/engine/balances.go
index 02fbf6fbe..043ea7164 100644
--- a/engine/balances.go
+++ b/engine/balances.go
@@ -26,6 +26,7 @@ import (
"strings"
"time"
+ "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
)
@@ -195,7 +196,7 @@ func (b *Balance) Clone() *Balance {
func (b *Balance) getMatchingPrefixAndDestID(dest string) (prefix, destId string) {
if len(b.DestinationIDs) != 0 && b.DestinationIDs[utils.ANY] == false {
for _, p := range utils.SplitPrefix(dest, MIN_PREFIX_MATCH) {
- if x, ok := CacheGet(utils.DESTINATION_PREFIX + p); ok {
+ if x, ok := cache2go.Get(utils.DESTINATION_PREFIX + p); ok {
destIDs := x.(map[string]struct{})
for dID := range destIDs {
if b.DestinationIDs[dID] == true {
diff --git a/engine/callcost.go b/engine/callcost.go
index 3fd7dae13..fb8db768d 100644
--- a/engine/callcost.go
+++ b/engine/callcost.go
@@ -21,6 +21,7 @@ import (
"errors"
"time"
+ "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
)
@@ -235,7 +236,7 @@ func (cc *CallCost) MatchCCFilter(bf *BalanceFilter) bool {
foundMatchingDestID := false
if bf.DestinationIDs != nil && cc.Destination != "" {
for _, p := range utils.SplitPrefix(cc.Destination, MIN_PREFIX_MATCH) {
- if x, ok := CacheGet(utils.DESTINATION_PREFIX + p); ok {
+ if x, ok := cache2go.Get(utils.DESTINATION_PREFIX + p); ok {
destIds := x.(map[string]struct{})
for filterDestID := range *bf.DestinationIDs {
if _, ok := destIds[filterDestID]; ok {
diff --git a/engine/calldesc.go b/engine/calldesc.go
index d6a0e8ceb..91c36f59b 100644
--- a/engine/calldesc.go
+++ b/engine/calldesc.go
@@ -27,6 +27,7 @@ import (
"strings"
"time"
+ "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
"github.com/cgrates/rpcclient"
)
@@ -882,9 +883,9 @@ func (cd *CallDescriptor) RefundRounding() error {
}
func (cd *CallDescriptor) FlushCache() (err error) {
- CacheFlush()
- ratingStorage.CacheRatingAll("FlushCache")
- accountingStorage.CacheAccountingAll("FlushCache")
+ cache2go.Flush()
+ ratingStorage.PreloadRatingCache()
+ accountingStorage.PreloadAccountingCache()
return nil
}
@@ -1030,7 +1031,7 @@ func (cd *CallDescriptor) GetLCR(stats rpcclient.RpcClientConnection, lcrFltr *L
}
ratingProfileSearchKey := utils.ConcatenatedKey(lcr.Direction, lcr.Tenant, lcrCost.Entry.RPCategory)
//log.Print("KEY: ", ratingProfileSearchKey)
- suppliers := CacheGetEntriesKeys(utils.RATING_PROFILE_PREFIX + ratingProfileSearchKey)
+ suppliers := cache2go.GetEntriesKeys(utils.RATING_PROFILE_PREFIX + ratingProfileSearchKey)
for _, supplier := range suppliers {
//log.Print("Supplier: ", supplier)
split := strings.Split(supplier, ":")
diff --git a/engine/calldesc_test.go b/engine/calldesc_test.go
index ab3bb981d..97852c0e2 100644
--- a/engine/calldesc_test.go
+++ b/engine/calldesc_test.go
@@ -102,8 +102,8 @@ func populateDB() {
}},
}
if accountingStorage != nil && ratingStorage != nil {
- ratingStorage.SetActions("TEST_ACTIONS", ats)
- ratingStorage.SetActions("TEST_ACTIONS_ORDER", ats1)
+ ratingStorage.SetActions("TEST_ACTIONS", ats, true)
+ ratingStorage.SetActions("TEST_ACTIONS_ORDER", ats1, true)
accountingStorage.SetAccount(broker)
accountingStorage.SetAccount(minu)
accountingStorage.SetAccount(minitsboy)
diff --git a/engine/cdrs.go b/engine/cdrs.go
index 2bd3c525b..0fb9b8cf3 100644
--- a/engine/cdrs.go
+++ b/engine/cdrs.go
@@ -28,6 +28,7 @@ import (
"strings"
"time"
+ "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/utils"
"github.com/cgrates/rpcclient"
@@ -97,20 +98,20 @@ type CdrServer struct {
aliases rpcclient.RpcClientConnection
stats rpcclient.RpcClientConnection
guard *GuardianLock
- responseCache *ResponseCache
+ responseCache *cache2go.ResponseCache
}
func (self *CdrServer) Timezone() string {
return self.cgrCfg.DefaultTimezone
}
func (self *CdrServer) SetTimeToLive(timeToLive time.Duration, out *int) error {
- self.responseCache = NewResponseCache(timeToLive)
+ self.responseCache = cache2go.NewResponseCache(timeToLive)
return nil
}
-func (self *CdrServer) getCache() *ResponseCache {
+func (self *CdrServer) getCache() *cache2go.ResponseCache {
if self.responseCache == nil {
- self.responseCache = NewResponseCache(0)
+ self.responseCache = cache2go.NewResponseCache(0)
}
return self.responseCache
}
@@ -499,10 +500,10 @@ func (self *CdrServer) V1ProcessCDR(cdr *CDR, reply *string) error {
return item.Err
}
if err := self.processCdr(cdr); err != nil {
- self.getCache().Cache(cacheKey, &CacheItem{Err: err})
+ self.getCache().Cache(cacheKey, &cache2go.CacheItem{Err: err})
return utils.NewErrServerError(err)
}
- self.getCache().Cache(cacheKey, &CacheItem{Value: utils.OK})
+ self.getCache().Cache(cacheKey, &cache2go.CacheItem{Value: utils.OK})
*reply = utils.OK
return nil
}
@@ -517,10 +518,10 @@ func (self *CdrServer) V1StoreSMCost(attr AttrCDRSStoreSMCost, reply *string) er
return item.Err
}
if err := self.storeSMCost(attr.Cost, attr.CheckDuplicate); err != nil {
- self.getCache().Cache(cacheKey, &CacheItem{Err: err})
+ self.getCache().Cache(cacheKey, &cache2go.CacheItem{Err: err})
return utils.NewErrServerError(err)
}
- self.getCache().Cache(cacheKey, &CacheItem{Value: utils.OK})
+ self.getCache().Cache(cacheKey, &cache2go.CacheItem{Value: utils.OK})
*reply = utils.OK
return nil
}
diff --git a/engine/cdrstats.go b/engine/cdrstats.go
index 98eb806c7..b24fc8b26 100644
--- a/engine/cdrstats.go
+++ b/engine/cdrstats.go
@@ -22,6 +22,7 @@ import (
"reflect"
"time"
+ "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/utils"
)
@@ -123,7 +124,7 @@ func (cs *CdrStats) AcceptCdr(cdr *CDR) bool {
if len(cs.DestinationIds) > 0 {
found := false
for _, p := range utils.SplitPrefix(cdr.Destination, MIN_PREFIX_MATCH) {
- if x, ok := CacheGet(utils.DESTINATION_PREFIX + p); ok {
+ if x, ok := cache2go.Get(utils.DESTINATION_PREFIX + p); ok {
destIds := x.(map[string]struct{})
for idID := range destIds {
if utils.IsSliceMember(cs.DestinationIds, idID) {
diff --git a/engine/destinations.go b/engine/destinations.go
index 2e439da8f..bbd38962a 100644
--- a/engine/destinations.go
+++ b/engine/destinations.go
@@ -22,6 +22,7 @@ import (
"encoding/json"
"strings"
+ "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
"github.com/cgrates/cgrates/history"
@@ -74,7 +75,7 @@ func (d *Destination) GetHistoryRecord(deleted bool) history.Record {
// Reverse search in cache to see if prefix belongs to destination id
func CachedDestHasPrefix(destId, prefix string) bool {
- if cached, ok := CacheGet(utils.DESTINATION_PREFIX + prefix); ok {
+ if cached, ok := cache2go.Get(utils.DESTINATION_PREFIX + prefix); ok {
_, found := cached.(map[string]struct{})[destId]
return found
}
@@ -83,7 +84,7 @@ func CachedDestHasPrefix(destId, prefix string) bool {
func CleanStalePrefixes(destIds []string) {
utils.Logger.Info("Cleaning stale dest prefixes: " + utils.ToJSON(destIds))
- prefixMap, err := CacheGetAllEntries(utils.DESTINATION_PREFIX)
+ prefixMap, err := cache2go.GetAllEntries(utils.DESTINATION_PREFIX)
if err != nil {
return
}
@@ -94,7 +95,7 @@ func CleanStalePrefixes(destIds []string) {
if _, found := dIDs[searchedDID]; found {
if len(dIDs) == 1 {
// remove de prefix from cache
- CacheRemKey(utils.DESTINATION_PREFIX + prefix)
+ cache2go.RemKey(utils.DESTINATION_PREFIX + prefix)
} else {
// delete the destination from list and put the new list in chache
delete(dIDs, searchedDID)
@@ -103,7 +104,7 @@ func CleanStalePrefixes(destIds []string) {
}
}
if changed {
- CacheSet(utils.DESTINATION_PREFIX+prefix, dIDs)
+ cache2go.Set(utils.DESTINATION_PREFIX+prefix, dIDs)
}
}
}
diff --git a/engine/destinations_test.go b/engine/destinations_test.go
index 67ae42c02..b0f7ca9af 100644
--- a/engine/destinations_test.go
+++ b/engine/destinations_test.go
@@ -21,6 +21,7 @@ package engine
import (
"encoding/json"
+ "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
"testing"
@@ -82,7 +83,7 @@ func TestDestinationGetExists(t *testing.T) {
func TestDestinationGetExistsCache(t *testing.T) {
ratingStorage.GetDestination("NAT")
- if _, ok := CacheGet(utils.DESTINATION_PREFIX + "0256"); !ok {
+ if _, ok := cache2go.Get(utils.DESTINATION_PREFIX + "0256"); !ok {
t.Error("Destination not cached:", err)
}
}
@@ -96,7 +97,7 @@ func TestDestinationGetNotExists(t *testing.T) {
func TestDestinationGetNotExistsCache(t *testing.T) {
ratingStorage.GetDestination("not existing")
- if d, ok := CacheGet("not existing"); ok {
+ if d, ok := cache2go.Get("not existing"); ok {
t.Error("Bad destination cached: ", d)
}
}
@@ -127,17 +128,17 @@ func TestNonCachedDestWrongPrefix(t *testing.T) {
func TestCleanStalePrefixes(t *testing.T) {
x := struct{}{}
- CacheSet(utils.DESTINATION_PREFIX+"1", map[string]struct{}{"D1": x, "D2": x})
- CacheSet(utils.DESTINATION_PREFIX+"2", map[string]struct{}{"D1": x})
- CacheSet(utils.DESTINATION_PREFIX+"3", map[string]struct{}{"D2": x})
+ cache2go.Set(utils.DESTINATION_PREFIX+"1", map[string]struct{}{"D1": x, "D2": x})
+ cache2go.Set(utils.DESTINATION_PREFIX+"2", map[string]struct{}{"D1": x})
+ cache2go.Set(utils.DESTINATION_PREFIX+"3", map[string]struct{}{"D2": x})
CleanStalePrefixes([]string{"D1"})
- if r, ok := CacheGet(utils.DESTINATION_PREFIX + "1"); !ok || len(r.(map[string]struct{})) != 1 {
+ if r, ok := cache2go.Get(utils.DESTINATION_PREFIX + "1"); !ok || len(r.(map[string]struct{})) != 1 {
t.Error("Error cleaning stale destination ids", r)
}
- if r, ok := CacheGet(utils.DESTINATION_PREFIX + "2"); ok {
+ if r, ok := cache2go.Get(utils.DESTINATION_PREFIX + "2"); ok {
t.Error("Error removing stale prefix: ", r)
}
- if r, ok := CacheGet(utils.DESTINATION_PREFIX + "3"); !ok || len(r.(map[string]struct{})) != 1 {
+ if r, ok := cache2go.Get(utils.DESTINATION_PREFIX + "3"); !ok || len(r.(map[string]struct{})) != 1 {
t.Error("Error performing stale cleaning: ", r)
}
}
diff --git a/engine/handler_derivedcharging.go b/engine/handler_derivedcharging.go
index ebd5bbfd0..7dd01b727 100644
--- a/engine/handler_derivedcharging.go
+++ b/engine/handler_derivedcharging.go
@@ -19,6 +19,7 @@ along with this program. If not, see
package engine
import (
+ "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
)
@@ -47,7 +48,7 @@ func DerivedChargersMatchesDest(dcs *utils.DerivedChargers, dest string) bool {
}
// check destination ids
for _, p := range utils.SplitPrefix(dest, MIN_PREFIX_MATCH) {
- if x, ok := CacheGet(utils.DESTINATION_PREFIX + p); ok {
+ if x, ok := cache2go.Get(utils.DESTINATION_PREFIX + p); ok {
destIds := x.(map[string]struct{})
for dId := range destIds {
includeDest, found := dcs.DestinationIDs[dId]
diff --git a/engine/lcr.go b/engine/lcr.go
index c8808d5e9..86c90b41c 100644
--- a/engine/lcr.go
+++ b/engine/lcr.go
@@ -26,6 +26,7 @@ import (
"strings"
"time"
+ "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/utils"
)
@@ -279,7 +280,7 @@ func (es LCREntriesSorter) Sort() {
func (lcra *LCRActivation) GetLCREntryForPrefix(destination string) *LCREntry {
var potentials LCREntriesSorter
for _, p := range utils.SplitPrefix(destination, MIN_PREFIX_MATCH) {
- if x, ok := CacheGet(utils.DESTINATION_PREFIX + p); ok {
+ if x, ok := cache2go.Get(utils.DESTINATION_PREFIX + p); ok {
destIds := x.(map[string]struct{})
for dId := range destIds {
diff --git a/engine/libtest.go b/engine/libtest.go
index b0f56e327..027dfc770 100644
--- a/engine/libtest.go
+++ b/engine/libtest.go
@@ -47,7 +47,7 @@ func InitDataDb(cfg *config.CGRConfig) error {
return err
}
}
- ratingDb.CacheRatingAll("ConfigureAccountingStorage")
+ ratingDb.PreloadRatingCache()
CheckVersion(accountDb) // Write version before starting
return nil
}
diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go
index 42b7195cd..ab9c19fc5 100644
--- a/engine/loader_csv_test.go
+++ b/engine/loader_csv_test.go
@@ -333,8 +333,8 @@ func init() {
log.Print("error in LoadResourceLimits:", err)
}
csvr.WriteToDatabase(false, false)
- ratingStorage.CacheRatingAll("LoaderCSVTests")
- accountingStorage.CacheAccountingAll("LoaderCSVTests")
+ ratingStorage.PreloadRatingCache()
+ accountingStorage.PreloadAccountingCache()
}
func TestLoadDestinations(t *testing.T) {
diff --git a/engine/loader_local_test.go b/engine/loader_local_test.go
index 1626ba107..fa06e4d03 100644
--- a/engine/loader_local_test.go
+++ b/engine/loader_local_test.go
@@ -293,7 +293,7 @@ func TestLoadIndividualProfiles(t *testing.T) {
for rpId := range rpfs {
rp, _ := utils.NewTPRatingProfileFromKeyId(utils.TEST_SQL, loadId, rpId)
mrp := APItoModelRatingProfile(rp)
- if err := loader.LoadRatingProfilesFiltered(&mrp[0]); err != nil {
+ if err := loader.LoadRatingProfilesFiltered(&mrp[0], true); err != nil {
t.Fatalf("Could not load ratingProfile with id: %s, error: %s", rpId, err.Error())
}
}
@@ -312,7 +312,7 @@ func TestLoadIndividualProfiles(t *testing.T) {
for dcId := range dcs {
mdc := &TpDerivedCharger{Tpid: utils.TEST_SQL, Loadid: loadId}
mdc.SetDerivedChargersId(dcId)
- if err := loader.LoadDerivedChargersFiltered(mdc, true); err != nil {
+ if err := loader.LoadDerivedChargersFiltered(mdc, true, true); err != nil {
t.Fatalf("Could not load derived charger with id: %s, error: %s", dcId, err.Error())
}
}
@@ -329,7 +329,7 @@ func TestLoadIndividualProfiles(t *testing.T) {
t.Fatal("Could not convert cdr stats")
}
for id := range cds {
- if err := loader.LoadCdrStatsFiltered(id, true); err != nil {
+ if err := loader.LoadCdrStatsFiltered(id, true, true); err != nil {
t.Fatalf("Could not load cdr stats with id: %s, error: %s", id, err.Error())
}
}
@@ -353,7 +353,7 @@ func TestLoadIndividualProfiles(t *testing.T) {
t.Fatal("Could not retrieve aliases")
} else {
for _, al := range aliases {
- if found, err := loader.LoadAliasesFiltered(&al); found && err != nil {
+ if found, err := loader.LoadAliasesFiltered(&al, true); found && err != nil {
t.Fatalf("Could not load aliase with id: %s, error: %s", al.GetId(), err.Error())
}
}
@@ -372,7 +372,7 @@ func TestLoadIndividualProfiles(t *testing.T) {
aa, _ := utils.NewTPAccountActionsFromKeyId(utils.TEST_SQL, loadId, aaId)
maa := APItoModelAccountAction(aa)
- if err := loader.LoadAccountActionsFiltered(maa); err != nil {
+ if err := loader.LoadAccountActionsFiltered(maa, true); err != nil {
t.Fatalf("Could not load account actions with id: %s, error: %s", aaId, err.Error())
}
}
diff --git a/engine/ratingplan_test.go b/engine/ratingplan_test.go
index cd45f9a7c..9747480df 100644
--- a/engine/ratingplan_test.go
+++ b/engine/ratingplan_test.go
@@ -449,7 +449,7 @@ func BenchmarkRatingPlanRestore(b *testing.B) {
EndTime: "15:00:00"}}
rp := &RatingPlan{Id: "test"}
rp.AddRateInterval("NAT", i)
- ratingStorage.SetRatingPlan(rp)
+ ratingStorage.SetRatingPlan(rp, false)
b.ResetTimer()
for i := 0; i < b.N; i++ {
ratingStorage.GetRatingPlan(rp.Id, true)
diff --git a/engine/ratingprofile.go b/engine/ratingprofile.go
index 095a83b6c..b17f7436c 100644
--- a/engine/ratingprofile.go
+++ b/engine/ratingprofile.go
@@ -25,6 +25,7 @@ import (
"strings"
"time"
+ "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/history"
"github.com/cgrates/cgrates/utils"
)
@@ -173,7 +174,7 @@ func (rpf *RatingProfile) GetRatingPlansForPrefix(cd *CallDescriptor) (err error
}
} else {
for _, p := range utils.SplitPrefix(cd.Destination, MIN_PREFIX_MATCH) {
- if x, ok := CacheGet(utils.DESTINATION_PREFIX + p); ok {
+ if x, ok := cache2go.Get(utils.DESTINATION_PREFIX + p); ok {
destIds := x.(map[string]struct{})
var bestWeight float64
for dID := range destIds {
diff --git a/engine/reqfilter.go b/engine/reqfilter.go
index 67aef78df..9c709b645 100644
--- a/engine/reqfilter.go
+++ b/engine/reqfilter.go
@@ -24,6 +24,7 @@ import (
"strconv"
"strings"
+ "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
"github.com/cgrates/rpcclient"
)
@@ -159,7 +160,7 @@ func (fltr *RequestFilter) passDestinations(req interface{}, extraFieldsLabel st
return false, err
}
for _, p := range utils.SplitPrefix(dst, MIN_PREFIX_MATCH) {
- if x, ok := CacheGet(utils.DESTINATION_PREFIX + p); ok {
+ if x, ok := cache2go.Get(utils.DESTINATION_PREFIX + p); ok {
destIds := x.(map[string]struct{})
for dID := range destIds {
for _, valDstID := range fltr.Values {
diff --git a/engine/reqfilter_test.go b/engine/reqfilter_test.go
index cb0eca74e..86590d917 100644
--- a/engine/reqfilter_test.go
+++ b/engine/reqfilter_test.go
@@ -22,6 +22,7 @@ import (
"testing"
"time"
+ "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
)
@@ -118,7 +119,7 @@ func TestPassRSRFields(t *testing.T) {
func TestPassDestinations(t *testing.T) {
x := struct{}{}
- CacheSet(utils.DESTINATION_PREFIX+"+49", map[string]struct{}{"DE": x, "EU_LANDLINE": x})
+ cache2go.Set(utils.REVERSE_DESTINATION_PREFIX+"+49", map[string]struct{}{"DE": x, "EU_LANDLINE": x})
cd := &CallDescriptor{Direction: "*out", Category: "call", Tenant: "cgrates.org", Subject: "dan", Destination: "+4986517174963",
TimeStart: time.Date(2013, time.October, 7, 14, 50, 0, 0, time.UTC), TimeEnd: time.Date(2013, time.October, 7, 14, 52, 12, 0, time.UTC),
DurationIndex: 132 * time.Second, ExtraFields: map[string]string{"navigation": "off"}}
diff --git a/engine/reslimiter.go b/engine/reslimiter.go
index bdb1bf83b..68bf29ec3 100644
--- a/engine/reslimiter.go
+++ b/engine/reslimiter.go
@@ -25,6 +25,7 @@ import (
"sync"
"time"
+ "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/utils"
"github.com/cgrates/rpcclient"
@@ -61,16 +62,16 @@ func (rls *ResourceLimiterService) indexStringFilters(rlIDs []string) error {
newStringIndexes := make(map[string]map[string]utils.StringMap) // Index it transactionally
var cacheIDsToIndex []string // Cache keys of RLs to be indexed
if rlIDs == nil {
- cacheIDsToIndex = CacheGetEntriesKeys(utils.ResourceLimitsPrefix)
+ cacheIDsToIndex = cache2go.GetEntriesKeys(utils.ResourceLimitsPrefix)
} else {
for _, rlID := range rlIDs {
cacheIDsToIndex = append(cacheIDsToIndex, utils.ResourceLimitsPrefix+rlID)
}
}
for _, cacheKey := range cacheIDsToIndex {
- x, err := CacheGet(cacheKey)
- if err != nil {
- return err
+ x, ok := cache2go.Get(cacheKey)
+ if !ok {
+ return utils.ErrNotFound
}
rl := x.(*ResourceLimit)
for _, fltr := range rl.Filters {
@@ -124,7 +125,7 @@ func (rls *ResourceLimiterService) cacheResourceLimits(loadID string, rlIDs []st
} else if len(rlIDs) != 0 {
utils.Logger.Info(fmt.Sprintf(" Start caching resource limits with ids: %+v", rlIDs))
}
- if err := rls.dataDB.CacheAccountingPrefixValues(loadID, map[string][]string{utils.ResourceLimitsPrefix: rlIDs}); err != nil {
+ if err := rls.dataDB.PreloadCacheForPrefix(utils.ResourceLimitsPrefix); err != nil {
return err
}
utils.Logger.Info(" Done caching resource limits")
diff --git a/engine/reslimiter_test.go b/engine/reslimiter_test.go
index f2777c6fe..659fecc12 100644
--- a/engine/reslimiter_test.go
+++ b/engine/reslimiter_test.go
@@ -23,6 +23,7 @@ import (
"testing"
"time"
+ "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
)
@@ -51,7 +52,7 @@ func TestIndexStringFilters(t *testing.T) {
},
}
for _, rl := range rls {
- CacheSet(utils.ResourceLimitsPrefix+rl.ID, rl)
+ cache2go.Set(utils.ResourceLimitsPrefix+rl.ID, rl)
}
rLS := new(ResourceLimiterService)
eIndexes := map[string]map[string]utils.StringMap{
@@ -88,7 +89,7 @@ func TestIndexStringFilters(t *testing.T) {
ActivationTime: time.Date(2014, 7, 3, 13, 43, 0, 1, time.UTC),
Limit: 1,
}
- CacheSet(utils.ResourceLimitsPrefix+rl3.ID, rl3)
+ cache2go.Set(utils.ResourceLimitsPrefix+rl3.ID, rl3)
eIndexes = map[string]map[string]utils.StringMap{
"Account": map[string]utils.StringMap{
"1001": utils.StringMap{
diff --git a/engine/responder.go b/engine/responder.go
index 6de84a947..0a6404fb4 100644
--- a/engine/responder.go
+++ b/engine/responder.go
@@ -28,6 +28,7 @@ import (
"time"
"github.com/cgrates/cgrates/balancer2go"
+ "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/utils"
"github.com/cgrates/rpcclient"
@@ -53,17 +54,17 @@ type Responder struct {
Timeout time.Duration
Timezone string
cnt int64
- responseCache *ResponseCache
+ responseCache *cache2go.ResponseCache
}
func (rs *Responder) SetTimeToLive(timeToLive time.Duration, out *int) error {
- rs.responseCache = NewResponseCache(timeToLive)
+ rs.responseCache = cache2go.NewResponseCache(timeToLive)
return nil
}
-func (rs *Responder) getCache() *ResponseCache {
+func (rs *Responder) getCache() *cache2go.ResponseCache {
if rs.responseCache == nil {
- rs.responseCache = NewResponseCache(0)
+ rs.responseCache = cache2go.NewResponseCache(0)
}
return rs.responseCache
}
@@ -181,7 +182,7 @@ func (rs *Responder) MaxDebit(arg *CallDescriptor, reply *CallCost) (err error)
} else {
r, e := arg.MaxDebit()
if e != nil {
- rs.getCache().Cache(cacheKey, &CacheItem{
+ rs.getCache().Cache(cacheKey, &cache2go.CacheItem{
Err: e,
})
return e
@@ -189,7 +190,7 @@ func (rs *Responder) MaxDebit(arg *CallDescriptor, reply *CallCost) (err error)
*reply = *r
}
}
- rs.getCache().Cache(cacheKey, &CacheItem{
+ rs.getCache().Cache(cacheKey, &cache2go.CacheItem{
Value: reply,
Err: err,
})
@@ -222,7 +223,7 @@ func (rs *Responder) RefundIncrements(arg *CallDescriptor, reply *float64) (err
Subject: arg.Subject,
Context: utils.ALIAS_CONTEXT_RATING,
}, arg, utils.EXTRA_FIELDS); err != nil && err != utils.ErrNotFound {
- rs.getCache().Cache(cacheKey, &CacheItem{
+ rs.getCache().Cache(cacheKey, &cache2go.CacheItem{
Err: err,
})
return err
@@ -233,7 +234,7 @@ func (rs *Responder) RefundIncrements(arg *CallDescriptor, reply *float64) (err
} else {
err = arg.RefundIncrements()
}
- rs.getCache().Cache(cacheKey, &CacheItem{
+ rs.getCache().Cache(cacheKey, &cache2go.CacheItem{
Value: reply,
Err: err,
})
@@ -266,7 +267,7 @@ func (rs *Responder) RefundRounding(arg *CallDescriptor, reply *float64) (err er
Subject: arg.Subject,
Context: utils.ALIAS_CONTEXT_RATING,
}, arg, utils.EXTRA_FIELDS); err != nil && err != utils.ErrNotFound {
- rs.getCache().Cache(cacheKey, &CacheItem{
+ rs.getCache().Cache(cacheKey, &cache2go.CacheItem{
Err: err,
})
return err
@@ -277,7 +278,7 @@ func (rs *Responder) RefundRounding(arg *CallDescriptor, reply *float64) (err er
} else {
err = arg.RefundRounding()
}
- rs.getCache().Cache(cacheKey, &CacheItem{
+ rs.getCache().Cache(cacheKey, &cache2go.CacheItem{
Value: reply,
Err: err,
})
@@ -332,7 +333,7 @@ func (rs *Responder) GetDerivedMaxSessionTime(ev *CDR, reply *float64) error {
}
// replace user profile fields
if err := LoadUserProfile(ev, utils.EXTRA_FIELDS); err != nil {
- rs.getCache().Cache(cacheKey, &CacheItem{Err: err})
+ rs.getCache().Cache(cacheKey, &cache2go.CacheItem{Err: err})
return err
}
// replace aliases
@@ -346,7 +347,7 @@ func (rs *Responder) GetDerivedMaxSessionTime(ev *CDR, reply *float64) error {
Subject: ev.Subject,
Context: utils.ALIAS_CONTEXT_RATING,
}, ev, utils.EXTRA_FIELDS); err != nil && err != utils.ErrNotFound {
- rs.getCache().Cache(cacheKey, &CacheItem{Err: err})
+ rs.getCache().Cache(cacheKey, &cache2go.CacheItem{Err: err})
return err
}
@@ -355,7 +356,7 @@ func (rs *Responder) GetDerivedMaxSessionTime(ev *CDR, reply *float64) error {
Account: ev.GetAccount(utils.META_DEFAULT), Subject: ev.GetSubject(utils.META_DEFAULT)}
dcs := &utils.DerivedChargers{}
if err := rs.GetDerivedChargers(attrsDC, dcs); err != nil {
- rs.getCache().Cache(cacheKey, &CacheItem{Err: err})
+ rs.getCache().Cache(cacheKey, &cache2go.CacheItem{Err: err})
return err
}
dcs, _ = dcs.AppendDefaultRun()
@@ -376,12 +377,12 @@ func (rs *Responder) GetDerivedMaxSessionTime(ev *CDR, reply *float64) error {
}
startTime, err := ev.GetSetupTime(utils.META_DEFAULT, rs.Timezone)
if err != nil {
- rs.getCache().Cache(cacheKey, &CacheItem{Err: err})
+ rs.getCache().Cache(cacheKey, &cache2go.CacheItem{Err: err})
return err
}
usage, err := ev.GetDuration(utils.META_DEFAULT)
if err != nil {
- rs.getCache().Cache(cacheKey, &CacheItem{Err: err})
+ rs.getCache().Cache(cacheKey, &cache2go.CacheItem{Err: err})
return err
}
if usage == 0 {
@@ -404,7 +405,7 @@ func (rs *Responder) GetDerivedMaxSessionTime(ev *CDR, reply *float64) error {
err = rs.GetMaxSessionTime(cd, &remainingDuration)
if err != nil {
*reply = 0
- rs.getCache().Cache(cacheKey, &CacheItem{Err: err})
+ rs.getCache().Cache(cacheKey, &cache2go.CacheItem{Err: err})
return err
}
if utils.IsSliceMember([]string{utils.META_POSTPAID, utils.POSTPAID}, ev.GetReqType(dc.RequestTypeField)) {
@@ -418,7 +419,7 @@ func (rs *Responder) GetDerivedMaxSessionTime(ev *CDR, reply *float64) error {
maxCallDuration = remainingDuration
}
}
- rs.getCache().Cache(cacheKey, &CacheItem{Value: maxCallDuration})
+ rs.getCache().Cache(cacheKey, &cache2go.CacheItem{Value: maxCallDuration})
*reply = maxCallDuration
return nil
}
@@ -463,7 +464,7 @@ func (rs *Responder) GetSessionRuns(ev *CDR, sRuns *[]*SessionRun) error {
//utils.Logger.Info(fmt.Sprintf("Derived chargers for: %+v", attrsDC))
dcs := &utils.DerivedChargers{}
if err := rs.GetDerivedChargers(attrsDC, dcs); err != nil {
- rs.getCache().Cache(cacheKey, &CacheItem{
+ rs.getCache().Cache(cacheKey, &cache2go.CacheItem{
Err: err,
})
return err
@@ -477,12 +478,12 @@ func (rs *Responder) GetSessionRuns(ev *CDR, sRuns *[]*SessionRun) error {
}
startTime, err := ev.GetAnswerTime(dc.AnswerTimeField, rs.Timezone)
if err != nil {
- rs.getCache().Cache(cacheKey, &CacheItem{Err: err})
+ rs.getCache().Cache(cacheKey, &cache2go.CacheItem{Err: err})
return errors.New("Error parsing answer event start time")
}
endTime, err := ev.GetEndTime("", rs.Timezone)
if err != nil {
- rs.getCache().Cache(cacheKey, &CacheItem{Err: err})
+ rs.getCache().Cache(cacheKey, &cache2go.CacheItem{Err: err})
return errors.New("Error parsing answer event end time")
}
extraFields := ev.GetExtraFields()
@@ -509,7 +510,7 @@ func (rs *Responder) GetSessionRuns(ev *CDR, sRuns *[]*SessionRun) error {
}
//utils.Logger.Info(fmt.Sprintf("RUNS: %v", len(sesRuns)))
*sRuns = sesRuns
- rs.getCache().Cache(cacheKey, &CacheItem{Value: sRuns})
+ rs.getCache().Cache(cacheKey, &cache2go.CacheItem{Value: sRuns})
return nil
}
@@ -552,12 +553,12 @@ func (rs *Responder) GetLCR(attrs *AttrGetLcr, reply *LCRCost) error {
Subject: cd.Subject,
Context: utils.ALIAS_CONTEXT_RATING,
}, cd, utils.EXTRA_FIELDS); err != nil && err != utils.ErrNotFound {
- rs.getCache().Cache(cacheKey, &CacheItem{Err: err})
+ rs.getCache().Cache(cacheKey, &cache2go.CacheItem{Err: err})
return err
}
lcrCost, err := attrs.CallDescriptor.GetLCR(rs.Stats, attrs.LCRFilter, attrs.Paginator)
if err != nil {
- rs.getCache().Cache(cacheKey, &CacheItem{Err: err})
+ rs.getCache().Cache(cacheKey, &cache2go.CacheItem{Err: err})
return err
}
if lcrCost.Entry != nil && lcrCost.Entry.Strategy == LCR_STRATEGY_LOAD {
@@ -565,7 +566,7 @@ func (rs *Responder) GetLCR(attrs *AttrGetLcr, reply *LCRCost) error {
suppl.Cost = -1 // In case of load distribution we don't calculate costs
}
}
- rs.getCache().Cache(cacheKey, &CacheItem{Value: lcrCost})
+ rs.getCache().Cache(cacheKey, &cache2go.CacheItem{Value: lcrCost})
*reply = *lcrCost
return nil
}
diff --git a/engine/responder_test.go b/engine/responder_test.go
index 7379812e0..71a1f6646 100644
--- a/engine/responder_test.go
+++ b/engine/responder_test.go
@@ -42,10 +42,7 @@ func TestResponderGetDerivedChargers(t *testing.T) {
CategoryField: "test", AccountField: "test", SubjectField: "test", DestinationField: "test", SetupTimeField: "test", AnswerTimeField: "test", UsageField: "test"}}}
rsponder = &Responder{}
attrs := &utils.AttrDerivedChargers{Tenant: "cgrates.org", Category: "call", Direction: "*out", Account: "responder_test", Subject: "responder_test"}
- if err := ratingStorage.SetDerivedChargers(utils.DerivedChargersKey(utils.OUT, utils.ANY, utils.ANY, utils.ANY, utils.ANY), cfgedDC); err != nil {
- t.Error(err)
- }
- if err := ratingStorage.CacheRatingPrefixes(utils.DERIVEDCHARGERS_PREFIX); err != nil {
+ if err := ratingStorage.SetDerivedChargers(utils.DerivedChargersKey(utils.OUT, utils.ANY, utils.ANY, utils.ANY, utils.ANY), cfgedDC, true); err != nil {
t.Error(err)
}
dcs := &utils.DerivedChargers{}
@@ -92,10 +89,9 @@ func TestResponderGetDerivedMaxSessionTime(t *testing.T) {
&utils.DerivedCharger{RunID: "extra3", RequestTypeField: "^" + utils.META_PSEUDOPREPAID, DirectionField: "*default", TenantField: "*default", CategoryField: "*default",
AccountField: "^rif", SubjectField: "^rif", DestinationField: "^+49151708707", SetupTimeField: "*default", AnswerTimeField: "*default", UsageField: "*default"},
}}
- if err := ratingStorage.SetDerivedChargers(keyCharger1, charger1); err != nil {
+ if err := ratingStorage.SetDerivedChargers(keyCharger1, charger1, true); err != nil {
t.Error("Error on setting DerivedChargers", err.Error())
}
- ratingStorage.CacheRatingAll("TestResponderGetDerivedMaxSessionTime")
if rifStoredAcnt, err := accountingStorage.GetAccount(utils.ConcatenatedKey(testTenant, "rif")); err != nil {
t.Error(err)
//} else if rifStoredAcnt.BalanceMap[utils.VOICE].Equal(rifsAccount.BalanceMap[utils.VOICE]) {
@@ -146,10 +142,9 @@ func TestResponderGetSessionRuns(t *testing.T) {
SetupTimeField: utils.META_DEFAULT, PDDField: utils.META_DEFAULT, AnswerTimeField: utils.META_DEFAULT, UsageField: utils.META_DEFAULT, SupplierField: utils.META_DEFAULT,
DisconnectCauseField: utils.META_DEFAULT}
charger1 := &utils.DerivedChargers{Chargers: []*utils.DerivedCharger{extra1DC, extra2DC, extra3DC}}
- if err := ratingStorage.SetDerivedChargers(keyCharger1, charger1); err != nil {
+ if err := ratingStorage.SetDerivedChargers(keyCharger1, charger1, true); err != nil {
t.Error("Error on setting DerivedChargers", err.Error())
}
- ratingStorage.CacheRatingAll("TestResponderGetSessionRuns")
sesRuns := make([]*SessionRun, 0)
eSRuns := []*SessionRun{
&SessionRun{DerivedCharger: extra1DC,
@@ -286,7 +281,7 @@ func TestResponderGetLCR(t *testing.T) {
},
}
for _, rpf := range []*RatingPlan{rp1, rp2, rp3} {
- if err := ratingStorage.SetRatingPlan(rpf); err != nil {
+ if err := ratingStorage.SetRatingPlan(rpf, true); err != nil {
t.Error(err)
}
}
@@ -322,7 +317,7 @@ func TestResponderGetLCR(t *testing.T) {
}},
}
for _, rpfl := range []*RatingProfile{danRpfl, rifRpfl, ivoRpfl} {
- if err := ratingStorage.SetRatingProfile(rpfl); err != nil {
+ if err := ratingStorage.SetRatingProfile(rpfl, true); err != nil {
t.Error(err)
}
}
@@ -372,18 +367,10 @@ func TestResponderGetLCR(t *testing.T) {
},
}
for _, lcr := range []*LCR{lcrStatic, lcrLowestCost, lcrQosThreshold, lcrQos, lcrLoad} {
- if err := ratingStorage.SetLCR(lcr); err != nil {
+ if err := ratingStorage.SetLCR(lcr, true); err != nil {
t.Error(err)
}
}
- if err := ratingStorage.CacheRatingPrefixValues("TestResponderGetLCR", map[string][]string{
- utils.DESTINATION_PREFIX: []string{utils.DESTINATION_PREFIX + dstDe.Id},
- utils.RATING_PLAN_PREFIX: []string{utils.RATING_PLAN_PREFIX + rp1.Id, utils.RATING_PLAN_PREFIX + rp2.Id, utils.RATING_PLAN_PREFIX + rp3.Id},
- utils.RATING_PROFILE_PREFIX: []string{utils.RATING_PROFILE_PREFIX + danRpfl.Id, utils.RATING_PROFILE_PREFIX + rifRpfl.Id, utils.RATING_PROFILE_PREFIX + ivoRpfl.Id},
- utils.LCR_PREFIX: []string{utils.LCR_PREFIX + lcrStatic.GetId(), utils.LCR_PREFIX + lcrLowestCost.GetId(), utils.LCR_PREFIX + lcrQosThreshold.GetId(), utils.LCR_PREFIX + lcrQos.GetId()},
- }); err != nil {
- t.Error(err)
- }
cdStatic := &CallDescriptor{
TimeStart: time.Date(2015, 04, 06, 17, 40, 0, 0, time.UTC),
TimeEnd: time.Date(2015, 04, 06, 17, 41, 0, 0, time.UTC),
diff --git a/engine/sharedgroup_test.go b/engine/sharedgroup_test.go
index fd71f1531..ae65caa5c 100644
--- a/engine/sharedgroup_test.go
+++ b/engine/sharedgroup_test.go
@@ -34,7 +34,7 @@ func TestSharedSetGet(t *testing.T) {
},
MemberIds: utils.NewStringMap("1", "2", "3"),
}
- err := ratingStorage.SetSharedGroup(sg)
+ err := ratingStorage.SetSharedGroup(sg, true)
if err != nil {
t.Error("Error storing Shared groudp: ", err)
}
diff --git a/engine/storage_interface.go b/engine/storage_interface.go
index de3e9a9cf..9b48ee9f4 100644
--- a/engine/storage_interface.go
+++ b/engine/storage_interface.go
@@ -33,41 +33,43 @@ type Storage interface {
Close()
Flush(string) error
GetKeysForPrefix(string) ([]string, error)
+ PreloadCacheForPrefix(string) error
+ RebuildReverseForPrefix(string) error
}
// Interface for storage providers.
type RatingStorage interface {
Storage
- CacheRatingAll(string) error
- CacheRatingPrefixes(string, ...string) error
- CacheRatingPrefixValues(string, map[string][]string) error
HasData(string, string) (bool, error)
- GetRatingPlan(string) (*RatingPlan, error)
- SetRatingPlan(*RatingPlan) error
- GetRatingProfile(string) (*RatingProfile, error)
- SetRatingProfile(*RatingProfile) error
+ PreloadRatingCache() error
+ GetRatingPlan(string, bool) (*RatingPlan, error)
+ SetRatingPlan(*RatingPlan, bool) error
+ GetRatingProfile(string, bool) (*RatingProfile, error)
+ SetRatingProfile(*RatingProfile, bool) error
RemoveRatingProfile(string) error
GetDestination(string) (*Destination, error)
SetDestination(*Destination) error
RemoveDestination(string) error
- //GetReverseDestination(string) ([]string, error)
- GetLCR(string) (*LCR, error)
- SetLCR(*LCR) error
+ SetReverseDestination(*Destination, bool) error
+ GetReverseDestination(string, bool) ([]string, error)
+ UpdateReverseDestination(*Destination, *Destination) error
+ GetLCR(string, bool) (*LCR, error)
+ SetLCR(*LCR, bool) error
SetCdrStats(*CdrStats) error
GetCdrStats(string) (*CdrStats, error)
GetAllCdrStats() ([]*CdrStats, error)
- GetDerivedChargers(string) (*utils.DerivedChargers, error)
- SetDerivedChargers(string, *utils.DerivedChargers) error
- GetActions(string) (Actions, error)
- SetActions(string, Actions) error
+ GetDerivedChargers(string, bool) (*utils.DerivedChargers, error)
+ SetDerivedChargers(string, *utils.DerivedChargers, bool) error
+ GetActions(string, bool) (Actions, error)
+ SetActions(string, Actions, bool) error
RemoveActions(string) error
- GetSharedGroup(string) (*SharedGroup, error)
- SetSharedGroup(*SharedGroup) error
- GetActionTriggers(string) (ActionTriggers, error)
- SetActionTriggers(string, ActionTriggers) error
+ GetSharedGroup(string, bool) (*SharedGroup, error)
+ SetSharedGroup(*SharedGroup, bool) error
+ GetActionTriggers(string, bool) (ActionTriggers, error)
+ SetActionTriggers(string, ActionTriggers, bool) error
RemoveActionTriggers(string) error
- GetActionPlan(string) (*ActionPlan, error)
- SetActionPlan(string, *ActionPlan, bool) error
+ GetActionPlan(string, bool) (*ActionPlan, error)
+ SetActionPlan(string, *ActionPlan, bool, bool) error
GetAllActionPlans() (map[string]*ActionPlan, error)
PushTask(*Task) error
PopTask() (*Task, error)
@@ -75,9 +77,7 @@ type RatingStorage interface {
type AccountingStorage interface {
Storage
- CacheAccountingAll(string) error
- CacheAccountingPrefixes(string, ...string) error
- CacheAccountingPrefixValues(string, map[string][]string) error
+ PreloadAccountingCache() error
GetAccount(string) (*Account, error)
SetAccount(*Account) error
RemoveAccount(string) error
@@ -90,14 +90,17 @@ type AccountingStorage interface {
GetUser(string) (*UserProfile, error)
GetUsers() ([]*UserProfile, error)
RemoveUser(string) error
- SetAlias(*Alias) error
- GetAlias(string) (*Alias, error)
+ SetAlias(*Alias, bool) error
+ GetAlias(string, bool) (*Alias, error)
RemoveAlias(string) error
+ SetReverseAlias(*Alias, bool) error
+ GetReverseAlias(string, bool) ([]string, error)
+ UpdateReverseAlias(*Alias, *Alias) error
GetResourceLimit(string, bool) (*ResourceLimit, error)
- SetResourceLimit(*ResourceLimit) error
+ SetResourceLimit(*ResourceLimit, bool) error
RemoveResourceLimit(string) error
GetLoadHistory(int, bool) ([]*utils.LoadInstance, error)
- AddLoadHistory(*utils.LoadInstance, int) error
+ AddLoadHistory(*utils.LoadInstance, int, bool) error
GetStructVersion() (*StructVersion, error)
SetStructVersion(*StructVersion) error
}
diff --git a/engine/storage_map.go b/engine/storage_map.go
index 2fd2df6d0..2b4539409 100644
--- a/engine/storage_map.go
+++ b/engine/storage_map.go
@@ -27,6 +27,7 @@ import (
"strings"
+ "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
)
@@ -39,12 +40,10 @@ type MapStorage struct {
}
func NewMapStorage() (*MapStorage, error) {
- CacheSetDumperPath("/tmp/cgrates")
return &MapStorage{dict: make(map[string][]byte), ms: NewCodecMsgpackMarshaler(), cacheDumpDir: "/tmp/cgrates"}, nil
}
func NewMapStorageJson() (*MapStorage, error) {
- CacheSetDumperPath("/tmp/cgrates")
return &MapStorage{dict: make(map[string][]byte), ms: new(JSONBufMarshaler), cacheDumpDir: "/tmp/cgrates"}, nil
}
@@ -57,19 +56,31 @@ func (ms *MapStorage) Flush(ignore string) error {
return nil
}
+func (ms *MapStorage) RebuildReverseForPrefix(prefix string) error {
+ return nil
+}
+
+func (ms *MapStorage) PreloadRatingCache() error {
+ return nil
+}
+
+func (ms *MapStorage) PreloadAccountingCache() error {
+ return nil
+}
+
+func (ms *MapStorage) PreloadCacheForPrefix(prefix string) error {
+ return nil
+}
+
func (ms *MapStorage) GetKeysForPrefix(prefix string) ([]string, error) {
ms.mu.RLock()
defer ms.mu.RUnlock()
- if x, ok := CacheGet(utils.GENERIC_PREFIX + "keys_" + prefix); ok {
- return x.([]string), nil
- }
keysForPrefix := make([]string, 0)
for key := range ms.dict {
if strings.HasPrefix(key, prefix) {
keysForPrefix = append(keysForPrefix, key)
}
}
- CacheSet(utils.GENERIC_PREFIX+"keys_"+prefix, r.List())
return keysForPrefix, nil
}
@@ -79,26 +90,23 @@ func (ms *MapStorage) HasData(categ, subject string) (bool, error) {
defer ms.mu.RUnlock()
switch categ {
case utils.DESTINATION_PREFIX, utils.RATING_PLAN_PREFIX, utils.RATING_PROFILE_PREFIX, utils.ACTION_PREFIX, utils.ACTION_PLAN_PREFIX, utils.ACCOUNT_PREFIX, utils.DERIVEDCHARGERS_PREFIX:
- if x, ok := CacheGet(utils.GENERIC_PREFIX + "has_" + category + "_" + subject); ok {
- return x.(bool), nil
- }
_, exists := ms.dict[categ+subject]
- CacheSet(utils.GENERIC_PREFIX+"has_"+category+"_"+subject, exists)
return exists, nil
}
- CacheSet(utils.GENERIC_PREFIX+"has_"+category+"_"+subject, false)
return false, errors.New("Unsupported HasData category")
}
-func (ms *MapStorage) GetRatingPlan(key string) (rp *RatingPlan, err error) {
+func (ms *MapStorage) GetRatingPlan(key string, skipCache bool) (rp *RatingPlan, err error) {
ms.mu.RLock()
defer ms.mu.RUnlock()
key = utils.RATING_PLAN_PREFIX + key
- if x, ok := CacheGet(key); ok {
- if x != nil {
- return x.(*RatingPlan), nil
+ if !skipCache {
+ if x, ok := cache2go.Get(key); ok {
+ if x != nil {
+ return x.(*RatingPlan), nil
+ }
+ return nil, utils.ErrNotFound
}
- return nil, utils.ErrNotFound
}
if values, ok := ms.dict[key]; ok {
b := bytes.NewBuffer(values)
@@ -114,10 +122,10 @@ func (ms *MapStorage) GetRatingPlan(key string) (rp *RatingPlan, err error) {
rp = new(RatingPlan)
err = ms.ms.Unmarshal(out, rp)
} else {
- CacheSet(key, nil)
+ cache2go.Set(key, nil)
return nil, utils.ErrNotFound
}
- CacheSet(key, rp)
+ cache2go.Set(key, rp)
return
}
@@ -135,20 +143,22 @@ func (ms *MapStorage) SetRatingPlan(rp *RatingPlan, cache bool) (err error) {
go historyScribe.Call("HistoryV1.Record", rp.GetHistoryRecord(), &response)
}
if cache && err == nil {
- CacheSet(utils.RATING_PLAN_PREFIX+rp.Id, rp)
+ cache2go.Set(utils.RATING_PLAN_PREFIX+rp.Id, rp)
}
return
}
-func (ms *MapStorage) GetRatingProfile(key string) (rpf *RatingProfile, err error) {
+func (ms *MapStorage) GetRatingProfile(key string, skipCache bool) (rpf *RatingProfile, err error) {
ms.mu.RLock()
defer ms.mu.RUnlock()
key = utils.RATING_PROFILE_PREFIX + key
- if x, ok := CacheGet(key); ok {
- if x != nil {
- return x.(*RatingProfile), nil
+ if !skipCache {
+ if x, ok := cache2go.Get(key); ok {
+ if x != nil {
+ return x.(*RatingProfile), nil
+ }
+ return nil, utils.ErrNotFound
}
- return nil, utils.ErrNotFound
}
if values, ok := ms.dict[key]; ok {
@@ -156,10 +166,10 @@ func (ms *MapStorage) GetRatingProfile(key string) (rpf *RatingProfile, err erro
err = ms.ms.Unmarshal(values, rpf)
} else {
- CacheSet(key, nil)
+ cache2go.Set(key, nil)
return nil, utils.ErrNotFound
}
- CacheSet(key, rpf)
+ cache2go.Set(key, rpf)
return
}
@@ -173,7 +183,7 @@ func (ms *MapStorage) SetRatingProfile(rpf *RatingProfile, cache bool) (err erro
go historyScribe.Call("HistoryV1.Record", rpf.GetHistoryRecord(false), &response)
}
if cache && err == nil {
- CacheSet(utils.RATING_PROFILE_PREFIX+rpf.Id, rpf)
+ cache2go.Set(utils.RATING_PROFILE_PREFIX+rpf.Id, rpf)
}
return
}
@@ -184,7 +194,7 @@ func (ms *MapStorage) RemoveRatingProfile(key string) (err error) {
for k := range ms.dict {
if strings.HasPrefix(k, key) {
delete(ms.dict, key)
- CacheRemKey(k)
+ cache2go.RemKey(k)
response := 0
rpf := &RatingProfile{Id: key}
if historyScribe != nil {
@@ -195,23 +205,25 @@ func (ms *MapStorage) RemoveRatingProfile(key string) (err error) {
return
}
-func (ms *MapStorage) GetLCR(key string) (lcr *LCR, err error) {
+func (ms *MapStorage) GetLCR(key string, skipCache bool) (lcr *LCR, err error) {
ms.mu.RLock()
defer ms.mu.RUnlock()
key = utils.LCR_PREFIX + key
- if x, ok := CacheGet(key); ok {
- if x != nil {
- return x.(*LCR), nil
+ if !skipCache {
+ if x, ok := cache2go.Get(key); ok {
+ if x != nil {
+ return x.(*LCR), nil
+ }
+ return nil, utils.ErrNotFound
}
- return nil, utils.ErrNotFound
}
if values, ok := ms.dict[key]; ok {
err = ms.ms.Unmarshal(values, &lcr)
} else {
- CacheSet(key, nil)
+ cache2go.Set(key, nil)
return nil, utils.ErrNotFound
}
- CacheSet(key, lcr)
+ cache2go.Set(key, lcr)
return
}
@@ -221,7 +233,7 @@ func (ms *MapStorage) SetLCR(lcr *LCR, cache bool) (err error) {
result, err := ms.ms.Marshal(lcr)
ms.dict[utils.LCR_PREFIX+lcr.GetId()] = result
if cache && err == nil {
- CacheSet(utils.LCR_PREFIX+lcr.GetId(), lcr)
+ cache2go.Set(utils.LCR_PREFIX+lcr.GetId(), lcr)
}
return
}
@@ -243,17 +255,13 @@ func (ms *MapStorage) GetDestination(key string) (dest *Destination, err error)
r.Close()
dest = new(Destination)
err = ms.ms.Unmarshal(out, dest)
- // create optimized structure
- for _, p := range dest.Prefixes {
- CachePush(utils.DESTINATION_PREFIX+p, dest.Id)
- }
} else {
return nil, utils.ErrNotFound
}
return
}
-func (ms *MapStorage) SetDestination(dest *Destination, cache bool) (err error) {
+func (ms *MapStorage) SetDestination(dest *Destination) (err error) {
ms.mu.Lock()
defer ms.mu.Unlock()
result, err := ms.ms.Marshal(dest)
@@ -266,33 +274,46 @@ func (ms *MapStorage) SetDestination(dest *Destination, cache bool) (err error)
if historyScribe != nil {
go historyScribe.Call("HistoryV1.Record", dest.GetHistoryRecord(false), &response)
}
- if cache && err == nil {
- CacheSet(utils.DESTINATION_PREFIX+dest.Id, dest)
- }
+ return
+}
+
+func (ms *MapStorage) GetReverseDestination(prefix string, skipCache bool) (ids []string, err error) {
+ return
+}
+
+func (ms *MapStorage) SetReverseDestination(dest *Destination, cache bool) (err error) {
+
return
}
func (ms *MapStorage) RemoveDestination(destID string) (err error) {
+
return
}
-func (ms *MapStorage) GetActions(key string) (as Actions, err error) {
+func (ms *MapStorage) UpdateReverseDestination(oldDest, newDest *Destination) error {
+ return nil
+}
+
+func (ms *MapStorage) GetActions(key string, skipCache bool) (as Actions, err error) {
ms.mu.RLock()
defer ms.mu.RUnlock()
key = utils.ACTION_PREFIX + key
- if x, ok := CacheGet(key); ok {
- if x != nil {
- return x.(Actions), nil
+ if !skipCache {
+ if x, ok := cache2go.Get(key); ok {
+ if x != nil {
+ return x.(Actions), nil
+ }
+ return nil, utils.ErrNotFound
}
- return nil, utils.ErrNotFound
}
if values, ok := ms.dict[key]; ok {
err = ms.ms.Unmarshal(values, &as)
} else {
- CacheSet(key, nil)
+ cache2go.Set(key, nil)
return nil, utils.ErrNotFound
}
- CacheSet(key, as)
+ cache2go.Set(key, as)
return
}
@@ -302,7 +323,7 @@ func (ms *MapStorage) SetActions(key string, as Actions, cache bool) (err error)
result, err := ms.ms.Marshal(&as)
ms.dict[utils.ACTION_PREFIX+key] = result
if cache && err == nil {
- CacheSet(utils.ACTION_PREFIX+key, as)
+ cache2go.Set(utils.ACTION_PREFIX+key, as)
}
return
}
@@ -311,27 +332,29 @@ func (ms *MapStorage) RemoveActions(key string) (err error) {
ms.mu.Lock()
defer ms.mu.Unlock()
delete(ms.dict, utils.ACTION_PREFIX+key)
- CacheRemKey(utils.ACTION_PREFIX + key)
+ cache2go.RemKey(utils.ACTION_PREFIX + key)
return
}
-func (ms *MapStorage) GetSharedGroup(key string) (sg *SharedGroup, err error) {
+func (ms *MapStorage) GetSharedGroup(key string, skipCache bool) (sg *SharedGroup, err error) {
ms.mu.RLock()
defer ms.mu.RUnlock()
key = utils.SHARED_GROUP_PREFIX + key
- if x, ok := CacheGet(key); ok {
- if x != nil {
- return x.(*SharedGroup), nil
+ if !skipCache {
+ if x, ok := cache2go.Get(key); ok {
+ if x != nil {
+ return x.(*SharedGroup), nil
+ }
+ return nil, utils.ErrNotFound
}
- return nil, utils.ErrNotFound
}
if values, ok := ms.dict[key]; ok {
err = ms.ms.Unmarshal(values, &sg)
if err == nil {
- CacheSet(key, sg)
+ cache2go.Set(key, sg)
}
} else {
- CacheSet(key, nil)
+ cache2go.Set(key, nil)
return nil, utils.ErrNotFound
}
return
@@ -343,7 +366,7 @@ func (ms *MapStorage) SetSharedGroup(sg *SharedGroup, cache bool) (err error) {
result, err := ms.ms.Marshal(sg)
ms.dict[utils.SHARED_GROUP_PREFIX+sg.Id] = result
if cache && err == nil {
- CacheSet(utils.SHARED_GROUP_PREFIX+sg.Id, sg)
+ cache2go.Set(utils.SHARED_GROUP_PREFIX+sg.Id, sg)
}
return
}
@@ -479,28 +502,30 @@ func (ms *MapStorage) RemoveUser(key string) error {
return nil
}
-func (ms *MapStorage) GetAlias(key string) (al *Alias, err error) {
+func (ms *MapStorage) GetAlias(key string, skipCache bool) (al *Alias, err error) {
ms.mu.RLock()
defer ms.mu.RUnlock()
+ origKey := key
key = utils.ALIASES_PREFIX + key
- if x, ok := CacheGet(key); ok {
- if x != nil {
- al = &Alias{Values: x.(AliasValues)}
- al.SetId(origKey)
- return al, nil
+ if !skipCache {
+ if x, ok := cache2go.Get(key); ok {
+ if x != nil {
+ al = &Alias{Values: x.(AliasValues)}
+ al.SetId(origKey)
+ return al, nil
+ }
+ return nil, utils.ErrNotFound
}
- return nil, utils.ErrNotFound
}
if values, ok := ms.dict[key]; ok {
al = &Alias{Values: make(AliasValues, 0)}
al.SetId(key[len(utils.ALIASES_PREFIX):])
err = ms.ms.Unmarshal(values, &al.Values)
if err == nil {
- CacheSet(key, al.Values)
- al.SetReverseCache()
+ cache2go.Set(key, al.Values)
}
} else {
- CacheSet(key, nil)
+ cache2go.Set(key, nil)
return nil, utils.ErrNotFound
}
return al, nil
@@ -513,32 +538,42 @@ func (ms *MapStorage) SetAlias(al *Alias, cache bool) error {
if err != nil {
return err
}
- ms.dict[utils.ALIASES_PREFIX+al.GetId()] = result
+ key := utils.ALIASES_PREFIX + al.GetId()
+ ms.dict[key] = result
if cache && err == nil {
- CacheSet(key, al.Values)
- al.SetReverseCache()
+ cache2go.Set(key, al.Values)
}
return nil
}
+func (ms *MapStorage) GetReverseAlias(reverseID string, skipCache bool) (ids []string, err error) {
+
+ return
+}
+
+func (ms *MapStorage) SetReverseAlias(al *Alias, cache bool) (err error) {
+
+ return
+}
+
func (ms *MapStorage) RemoveAlias(key string) error {
ms.mu.Lock()
defer ms.mu.Unlock()
- al := &Alias{}
- al.SetId(key)
key = utils.ALIASES_PREFIX + key
aliasValues := make(AliasValues, 0)
if values, ok := ms.dict[key]; ok {
ms.ms.Unmarshal(values, &aliasValues)
}
- al.Values = aliasValues
delete(ms.dict, key)
- al.RemoveReverseCache()
- CacheRemKey(key)
+ cache2go.RemKey(key)
return nil
}
-func (ms *MapStorage) GetLoadHistory(limitItems int) ([]*utils.LoadInstance, error) {
+func (ms *MapStorage) UpdateReverseAlias(oldAl, newAl *Alias) error {
+ return nil
+}
+
+func (ms *MapStorage) GetLoadHistory(limitItems int, skipCache bool) ([]*utils.LoadInstance, error) {
ms.mu.RLock()
defer ms.mu.RUnlock()
return nil, nil
@@ -550,23 +585,25 @@ func (ms *MapStorage) AddLoadHistory(*utils.LoadInstance, int, bool) error {
return nil
}
-func (ms *MapStorage) GetActionTriggers(key string) (atrs ActionTriggers, err error) {
+func (ms *MapStorage) GetActionTriggers(key string, skipCache bool) (atrs ActionTriggers, err error) {
ms.mu.RLock()
defer ms.mu.RUnlock()
key = utils.ACTION_TRIGGER_PREFIX + key
- if x, ok := CacheGet(key); ok {
- if x != nil {
- return x.(ActionTriggers), nil
+ if !skipCache {
+ if x, ok := cache2go.Get(key); ok {
+ if x != nil {
+ return x.(ActionTriggers), nil
+ }
+ return nil, utils.ErrNotFound
}
- return nil, utils.ErrNotFound
}
if values, ok := ms.dict[key]; ok {
err = ms.ms.Unmarshal(values, &atrs)
} else {
- CacheSet(key, nil)
+ cache2go.Set(key, nil)
return nil, utils.ErrNotFound
}
- CacheSet(key, atrs)
+ cache2go.Set(key, atrs)
return
}
@@ -581,7 +618,7 @@ func (ms *MapStorage) SetActionTriggers(key string, atrs ActionTriggers, cache b
result, err := ms.ms.Marshal(&atrs)
ms.dict[utils.ACTION_TRIGGER_PREFIX+key] = result
if cache && err == nil {
- CacheSet(utils.ACTION_TRIGGER_PREFIX+key, atrs)
+ cache2go.Set(utils.ACTION_TRIGGER_PREFIX+key, atrs)
}
return
}
@@ -590,27 +627,29 @@ func (ms *MapStorage) RemoveActionTriggers(key string) (err error) {
ms.mu.Lock()
defer ms.mu.Unlock()
delete(ms.dict, utils.ACTION_TRIGGER_PREFIX+key)
- CacheRemKey(key)
+ cache2go.RemKey(key)
return
}
-func (ms *MapStorage) GetActionPlan(key string) (ats *ActionPlan, err error) {
+func (ms *MapStorage) GetActionPlan(key string, skipCache bool) (ats *ActionPlan, err error) {
ms.mu.RLock()
defer ms.mu.RUnlock()
key = utils.ACTION_PLAN_PREFIX + key
- if x, ok := CacheGet(key); ok {
- if x != nil {
- return x.(*ActionPlan), nil
+ if !skipCache {
+ if x, ok := cache2go.Get(key); ok {
+ if x != nil {
+ return x.(*ActionPlan), nil
+ }
+ return nil, utils.ErrNotFound
}
- return nil, utils.ErrNotFond
}
if values, ok := ms.dict[key]; ok {
err = ms.ms.Unmarshal(values, &ats)
} else {
- CacheSet(key, nil)
+ cache2go.Set(key, nil)
return nil, utils.ErrNotFound
}
- CacheSet(key, ats)
+ cache2go.Set(key, ats)
return
}
@@ -620,7 +659,7 @@ func (ms *MapStorage) SetActionPlan(key string, ats *ActionPlan, overwrite, cach
defer ms.mu.Unlock()
// delete the key
delete(ms.dict, utils.ACTION_PLAN_PREFIX+key)
- CacheRemKey(utils.ACTION_PLAN_PREFIX + key)
+ cache2go.RemKey(utils.ACTION_PLAN_PREFIX + key)
return
}
if !overwrite {
@@ -639,7 +678,7 @@ func (ms *MapStorage) SetActionPlan(key string, ats *ActionPlan, overwrite, cach
result, err := ms.ms.Marshal(&ats)
ms.dict[utils.ACTION_PLAN_PREFIX+key] = result
if cache && err == nil {
- CacheSet(utils.ACTION_PLAN_PREFIX+key, at)
+ cache2go.Set(utils.ACTION_PLAN_PREFIX+key, ats)
}
return
}
@@ -647,7 +686,7 @@ func (ms *MapStorage) SetActionPlan(key string, ats *ActionPlan, overwrite, cach
func (ms *MapStorage) GetAllActionPlans() (ats map[string]*ActionPlan, err error) {
ms.mu.RLock()
defer ms.mu.RUnlock()
- apls, err := CacheGetAllEntries(utils.ACTION_PLAN_PREFIX)
+ apls, err := cache2go.GetAllEntries(utils.ACTION_PLAN_PREFIX)
if err != nil {
return nil, err
}
@@ -686,23 +725,25 @@ func (ms *MapStorage) PopTask() (t *Task, err error) {
return
}
-func (ms *MapStorage) GetDerivedChargers(key string) (dcs *utils.DerivedChargers, err error) {
+func (ms *MapStorage) GetDerivedChargers(key string, skipCache bool) (dcs *utils.DerivedChargers, err error) {
ms.mu.RLock()
defer ms.mu.RUnlock()
key = utils.DERIVEDCHARGERS_PREFIX + key
- if x, ok := CacheGet(key); ok {
- if x != nil {
- return x.(*utils.DerivedChargers), nil
+ if !skipCache {
+ if x, ok := cache2go.Get(key); ok {
+ if x != nil {
+ return x.(*utils.DerivedChargers), nil
+ }
+ return nil, utils.ErrNotFound
}
- return nil, utils.ErrNotFound
}
if values, ok := ms.dict[key]; ok {
err = ms.ms.Unmarshal(values, &dcs)
} else {
- CacheSet(key, nil)
+ cache2go.Set(key, nil)
return nil, utils.ErrNotFound
}
- CacheSet(key, dcs)
+ cache2go.Set(key, dcs)
return
}
@@ -711,13 +752,13 @@ func (ms *MapStorage) SetDerivedChargers(key string, dcs *utils.DerivedChargers,
defer ms.mu.Unlock()
if dcs == nil || len(dcs.Chargers) == 0 {
delete(ms.dict, utils.DERIVEDCHARGERS_PREFIX+key)
- CacheRemKey(utils.DERIVEDCHARGERS_PREFIX + key)
+ cache2go.RemKey(utils.DERIVEDCHARGERS_PREFIX + key)
return nil
}
result, err := ms.ms.Marshal(dcs)
ms.dict[utils.DERIVEDCHARGERS_PREFIX+key] = result
if cache && err == nil {
- CacheSet(key, dcs)
+ cache2go.Set(key, dcs)
}
return err
}
@@ -801,9 +842,10 @@ func (ms *MapStorage) GetStructVersion() (rsv *StructVersion, err error) {
func (ms *MapStorage) GetResourceLimit(id string, skipCache bool) (*ResourceLimit, error) {
return nil, nil
}
-func (ms *MapStorage) SetResourceLimit(rl *ResourceLimit) error {
+func (ms *MapStorage) SetResourceLimit(rl *ResourceLimit, cache bool) error {
return nil
}
+
func (ms *MapStorage) RemoveResourceLimit(id string) error {
return nil
}
diff --git a/engine/storage_mongo_datadb.go b/engine/storage_mongo_datadb.go
index cd3866dde..9cefc1aa1 100644
--- a/engine/storage_mongo_datadb.go
+++ b/engine/storage_mongo_datadb.go
@@ -26,6 +26,7 @@ import (
"io/ioutil"
"strings"
+ "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
@@ -285,11 +286,6 @@ func NewMongoStorage(host, port, db, user, pass string, cdrsIndexes []string, ca
if err = ndb.C(utils.TBLSMCosts).EnsureIndex(index); err != nil {
return nil, err
}
- if cacheDumpDir != "" {
- if err := CacheSetDumperPath(cacheDumpDir); err != nil {
- utils.Logger.Info(" init error: " + err.Error())
- }
- }
return &MongoStorage{db: db, session: session, ms: NewCodecMsgpackMarshaler(), cacheDumpDir: cacheDumpDir, loadHistorySize: loadHistorySize}, err
}
@@ -313,7 +309,23 @@ func (ms *MongoStorage) Flush(ignore string) (err error) {
return nil
}
-func (ms *MongoStorage) GetKeysForPrefix(prefix string, skipCache bool) ([]string, error) {
+func (ms *MongoStorage) RebuildReverseForPrefix(prefix string) error {
+ return nil
+}
+
+func (ms *MongoStorage) PreloadRatingCache() error {
+ return nil
+}
+
+func (ms *MongoStorage) PreloadAccountingCache() error {
+ return nil
+}
+
+func (ms *MongoStorage) PreloadCacheForPrefix(prefix string) error {
+ return nil
+}
+
+func (ms *MongoStorage) GetKeysForPrefix(prefix string) ([]string, error) {
var category, subject string
length := len(utils.DESTINATION_PREFIX)
if len(prefix) >= length {
@@ -322,12 +334,6 @@ func (ms *MongoStorage) GetKeysForPrefix(prefix string, skipCache bool) ([]strin
} else {
return nil, fmt.Errorf("unsupported prefix in GetKeysForPrefix: %s", prefix)
}
- if x, ok := CacheGet(utils.GENERIC_PREFIX + "keys_" + prefix); ok {
- if x != nil {
- return x.([]string), nil
- }
- return nil, utils.ErrNotFound
- }
var result []string
session := ms.session.Copy()
defer session.Close()
@@ -340,98 +346,82 @@ func (ms *MongoStorage) GetKeysForPrefix(prefix string, skipCache bool) ([]strin
for iter.Next(&keyResult) {
result = append(result, utils.DESTINATION_PREFIX+keyResult.Key)
}
- CacheSet(utils.GENERIC_PREFIX+"keys_"+prefix, result)
return result, nil
case utils.RATING_PLAN_PREFIX:
iter := db.C(colRpl).Find(bson.M{"key": bson.M{"$regex": bson.RegEx{Pattern: subject}}}).Select(bson.M{"key": 1}).Iter()
for iter.Next(&keyResult) {
result = append(result, utils.RATING_PLAN_PREFIX+keyResult.Key)
}
- CacheSet(utils.GENERIC_PREFIX+"keys_"+prefix, result)
return result, nil
case utils.RATING_PROFILE_PREFIX:
iter := db.C(colRpf).Find(bson.M{"id": bson.M{"$regex": bson.RegEx{Pattern: subject}}}).Select(bson.M{"id": 1}).Iter()
for iter.Next(&idResult) {
result = append(result, utils.RATING_PROFILE_PREFIX+idResult.Id)
}
- CacheSet(utils.GENERIC_PREFIX+"keys_"+prefix, result)
return result, nil
case utils.ACTION_PREFIX:
iter := db.C(colAct).Find(bson.M{"key": bson.M{"$regex": bson.RegEx{Pattern: subject}}}).Select(bson.M{"key": 1}).Iter()
for iter.Next(&keyResult) {
result = append(result, utils.ACTION_PREFIX+keyResult.Key)
}
- CacheSet(utils.GENERIC_PREFIX+"keys_"+prefix, result)
return result, nil
case utils.ACTION_PLAN_PREFIX:
iter := db.C(colApl).Find(bson.M{"key": bson.M{"$regex": bson.RegEx{Pattern: subject}}}).Select(bson.M{"key": 1}).Iter()
for iter.Next(&keyResult) {
result = append(result, utils.ACTION_PLAN_PREFIX+keyResult.Key)
}
- CacheSet(utils.GENERIC_PREFIX+"keys_"+prefix, result)
return result, nil
case utils.ACTION_TRIGGER_PREFIX:
iter := db.C(colAtr).Find(bson.M{"key": bson.M{"$regex": bson.RegEx{Pattern: subject}}}).Select(bson.M{"key": 1}).Iter()
for iter.Next(&keyResult) {
result = append(result, utils.ACTION_TRIGGER_PREFIX+keyResult.Key)
}
- CacheSet(utils.GENERIC_PREFIX+"keys_"+prefix, result)
return result, nil
case utils.ACCOUNT_PREFIX:
iter := db.C(colAcc).Find(bson.M{"id": bson.M{"$regex": bson.RegEx{Pattern: subject}}}).Select(bson.M{"id": 1}).Iter()
for iter.Next(&idResult) {
result = append(result, utils.ACCOUNT_PREFIX+idResult.Id)
}
- CacheSet(utils.GENERIC_PREFIX+"keys_"+prefix, result)
return result, nil
}
- CacheSet(utils.GENERIC_PREFIX+"keys_"+prefix, result)
return result, fmt.Errorf("unsupported prefix in GetKeysForPrefix: %s", prefix)
}
func (ms *MongoStorage) HasData(category, subject string) (bool, error) {
- if x, ok := CacheGet(utils.GENERIC_PREFIX + "has_" + category + "_" + subject); ok {
- return x.(bool), nil
- }
session := ms.session.Copy()
defer session.Close()
db := session.DB(ms.db)
switch category {
case utils.DESTINATION_PREFIX:
count, err := db.C(colDst).Find(bson.M{"key": subject}).Count()
- CacheSet(utils.GENERIC_PREFIX+"has_"+category+"_"+subject, count > 0)
return count > 0, err
case utils.RATING_PLAN_PREFIX:
count, err := db.C(colRpl).Find(bson.M{"key": subject}).Count()
- CacheSet(utils.GENERIC_PREFIX+"has_"+category+"_"+subject, count > 0)
return count > 0, err
case utils.RATING_PROFILE_PREFIX:
count, err := db.C(colRpf).Find(bson.M{"id": subject}).Count()
- CacheSet(utils.GENERIC_PREFIX+"has_"+category+"_"+subject, count > 0)
return count > 0, err
case utils.ACTION_PREFIX:
count, err := db.C(colAct).Find(bson.M{"key": subject}).Count()
- CacheSet(utils.GENERIC_PREFIX+"has_"+category+"_"+subject, count > 0)
return count > 0, err
case utils.ACTION_PLAN_PREFIX:
count, err := db.C(colApl).Find(bson.M{"key": subject}).Count()
- CacheSet(utils.GENERIC_PREFIX+"has_"+category+"_"+subject, count > 0)
return count > 0, err
case utils.ACCOUNT_PREFIX:
count, err := db.C(colAcc).Find(bson.M{"id": subject}).Count()
- CacheSet(utils.GENERIC_PREFIX+"has_"+category+"_"+subject, count > 0)
return count > 0, err
}
- CacheSet(utils.GENERIC_PREFIX+"has_"+category+"_"+subject, false)
return false, errors.New("unsupported category in HasData")
}
-func (ms *MongoStorage) GetRatingPlan(key string) (rp *RatingPlan, err error) {
- if x, ok := CacheGet(utils.RATING_PLAN_PREFIX + key); ok {
- if x != nil {
- return x.(*RatingPlan), nil
+func (ms *MongoStorage) GetRatingPlan(key string, skipCache bool) (rp *RatingPlan, err error) {
+ if !skipCache {
+ if x, ok := cache2go.Get(utils.RATING_PLAN_PREFIX + key); ok {
+ if x != nil {
+ return x.(*RatingPlan), nil
+ }
+ return nil, utils.ErrNotFound
}
- return nil, utils.ErrNotFound
}
rp = new(RatingPlan)
var kv struct {
@@ -457,7 +447,7 @@ func (ms *MongoStorage) GetRatingPlan(key string) (rp *RatingPlan, err error) {
return nil, err
}
}
- CacheSet(utils.RATING_PLAN_PREFIX+key, rp)
+ cache2go.Set(utils.RATING_PLAN_PREFIX+key, rp)
return
}
@@ -481,26 +471,28 @@ func (ms *MongoStorage) SetRatingPlan(rp *RatingPlan, cache bool) error {
historyScribe.Call("HistoryV1.Record", rp.GetHistoryRecord(), &response)
}
if cache && err == nil {
- CacheSet(utils.RATING_PLAN_PREFIX+rp.Id, rp)
+ cache2go.Set(utils.RATING_PLAN_PREFIX+rp.Id, rp)
}
return err
}
-func (ms *MongoStorage) GetRatingProfile(key string) (rp *RatingProfile, err error) {
- if x, ok := CacheGet(utils.RATING_PROFILE_PREFIX + key); ok {
- if x != nil {
- return x.(*RatingProfile), nil
+func (ms *MongoStorage) GetRatingProfile(key string, skipCache bool) (rp *RatingProfile, err error) {
+ if !skipCache {
+ if x, ok := cache2go.Get(utils.RATING_PROFILE_PREFIX + key); ok {
+ if x != nil {
+ return x.(*RatingProfile), nil
+ }
+ return nil, utils.ErrNotFound
}
- return nil, utils.ErrNotFound
}
rp = new(RatingProfile)
session, col := ms.conn(colRpf)
defer session.Close()
err = col.Find(bson.M{"id": key}).One(rp)
if err == nil {
- CacheSet(utils.RATING_PROFILE_PREFIX+key, rp)
+ cache2go.Set(utils.RATING_PROFILE_PREFIX+key, rp)
} else {
- CacheSet(utils.RATING_PROFILE_PREFIX+key, nil)
+ cache2go.Set(utils.RATING_PROFILE_PREFIX+key, nil)
}
return
}
@@ -514,7 +506,7 @@ func (ms *MongoStorage) SetRatingProfile(rp *RatingProfile, cache bool) error {
historyScribe.Call("HistoryV1.Record", rp.GetHistoryRecord(false), &response)
}
if cache && err == nil {
- CacheSet(utils.RATING_PROFILE_PREFIX+rpf.Id, rpf)
+ cache2go.Set(utils.RATING_PROFILE_PREFIX+rp.Id, rp)
}
return err
}
@@ -528,7 +520,7 @@ func (ms *MongoStorage) RemoveRatingProfile(key string) error {
if err := col.Remove(bson.M{"id": result.Id}); err != nil {
return err
}
- CacheRemKey(utils.RATING_PROFILE_PREFIX + key)
+ cache2go.RemKey(utils.RATING_PROFILE_PREFIX + key)
rpf := &RatingProfile{Id: result.Id}
if historyScribe != nil {
var response int
@@ -538,12 +530,14 @@ func (ms *MongoStorage) RemoveRatingProfile(key string) error {
return iter.Close()
}
-func (ms *MongoStorage) GetLCR(key string) (lcr *LCR, err error) {
- if x, ok := CacheGet(utils.LCR_PREFIX + key); ok {
- if x != nil {
- return x.(*LCR), nil
+func (ms *MongoStorage) GetLCR(key string, skipCache bool) (lcr *LCR, err error) {
+ if !skipCache {
+ if x, ok := cache2go.Get(utils.LCR_PREFIX + key); ok {
+ if x != nil {
+ return x.(*LCR), nil
+ }
+ return nil, utils.ErrNotFound
}
- return nil, utils.ErrNotFound
}
var result struct {
Key string
@@ -555,7 +549,7 @@ func (ms *MongoStorage) GetLCR(key string) (lcr *LCR, err error) {
if err == nil {
lcr = result.Value
}
- CacheSet(utils.LCR_PREFIX+key, lcr)
+ cache2go.Set(utils.LCR_PREFIX+key, lcr)
return
}
@@ -567,7 +561,7 @@ func (ms *MongoStorage) SetLCR(lcr *LCR, cache bool) error {
Value *LCR
}{lcr.GetId(), lcr})
if cache && err == nil {
- CacheSet(utils.LCR_PREFIX+lcr.GetId(), lcr)
+ cache2go.Set(utils.LCR_PREFIX+lcr.GetId(), lcr)
}
return err
}
@@ -596,17 +590,13 @@ func (ms *MongoStorage) GetDestination(key string) (result *Destination, err err
if err != nil {
return nil, err
}
- // create optimized structure
- for _, p := range result.Prefixes {
- CachePush(utils.DESTINATION_PREFIX+p, result.Id)
- }
}
if err != nil {
result = nil
}
return
}
-func (ms *MongoStorage) SetDestination(dest *Destination, cache bool) (err error) {
+func (ms *MongoStorage) SetDestination(dest *Destination) (err error) {
result, err := ms.ms.Marshal(dest)
if err != nil {
return err
@@ -625,9 +615,6 @@ func (ms *MongoStorage) SetDestination(dest *Destination, cache bool) (err error
var response int
historyScribe.Call("HistoryV1.Record", dest.GetHistoryRecord(false), &response)
}
- if cache && err == nil {
- CacheSet(utils.DESTINATION_PREFIX+dest.Id, dest)
- }
return
}
@@ -647,17 +634,31 @@ func (ms *MongoStorage) SetDestination(dest *Destination, cache bool) (err error
}
return
}*/
+func (ms *MongoStorage) GetReverseDestination(prefix string, skipCache bool) (ids []string, err error) {
+ return
+}
+
+func (ms *MongoStorage) SetReverseDestination(dest *Destination, cache bool) (err error) {
+
+ return
+}
func (ms *MongoStorage) RemoveDestination(destID string) (err error) {
return
}
-func (ms *MongoStorage) GetActions(key string) (as Actions, err error) {
- if x, ok := CacheGet(utils.ACTION_PREFIX + key); ok {
- if x != nil {
- return x.(Actions), nil
+func (ms *MongoStorage) UpdateReverseDestination(oldDest, newDest *Destination) error {
+ return nil
+}
+
+func (ms *MongoStorage) GetActions(key string, skipCache bool) (as Actions, err error) {
+ if !skipCache {
+ if x, ok := cache2go.Get(utils.ACTION_PREFIX + key); ok {
+ if x != nil {
+ return x.(Actions), nil
+ }
+ return nil, utils.ErrNotFound
}
- return nil, utils.ErrNotFound
}
var result struct {
Key string
@@ -669,7 +670,7 @@ func (ms *MongoStorage) GetActions(key string) (as Actions, err error) {
if err == nil {
as = result.Value
}
- CacheSet(utils.ACTION_PREFIX+key, as)
+ cache2go.Set(utils.ACTION_PREFIX+key, as)
return
}
@@ -681,7 +682,7 @@ func (ms *MongoStorage) SetActions(key string, as Actions, cache bool) error {
Value Actions
}{Key: key, Value: as})
if cache && err == nil {
- CacheSet(utils.ACTION_PREFIX+key, as)
+ cache2go.Set(utils.ACTION_PREFIX+key, as)
}
return err
}
@@ -692,21 +693,23 @@ func (ms *MongoStorage) RemoveActions(key string) error {
return col.Remove(bson.M{"key": key})
}
-func (ms *MongoStorage) GetSharedGroup(key string) (sg *SharedGroup, err error) {
- if x, ok := CacheGet(utils.SHARED_GROUP_PREFIX + key); ok {
- if x != nil {
- return x.(*SharedGroup), nil
+func (ms *MongoStorage) GetSharedGroup(key string, skipCache bool) (sg *SharedGroup, err error) {
+ if !skipCache {
+ if x, ok := cache2go.Get(utils.SHARED_GROUP_PREFIX + key); ok {
+ if x != nil {
+ return x.(*SharedGroup), nil
+ }
+ return nil, utils.ErrNotFound
}
- return nil, utils.ErrNotFound
}
session, col := ms.conn(colShg)
defer session.Close()
sg = &SharedGroup{}
err = col.Find(bson.M{"id": key}).One(sg)
if err == nil {
- CacheSet(utils.SHARED_GROUP_PREFIX+key, sg)
+ cache2go.Set(utils.SHARED_GROUP_PREFIX+key, sg)
} else {
- CacheSet(utils.SHARED_GROUP_PREFIX+key, nil)
+ cache2go.Set(utils.SHARED_GROUP_PREFIX+key, nil)
}
return
}
@@ -716,7 +719,7 @@ func (ms *MongoStorage) SetSharedGroup(sg *SharedGroup, cache bool) (err error)
defer session.Close()
_, err = col.Upsert(bson.M{"id": sg.Id}, sg)
if cache && err == nil {
- CacheSet(utils.SHARED_GROUP_PREFIX+sg.Id, sg)
+ cache2go.Set(utils.SHARED_GROUP_PREFIX+sg.Id, sg)
}
return err
}
@@ -859,14 +862,16 @@ func (ms *MongoStorage) RemoveUser(key string) (err error) {
return col.Remove(bson.M{"key": key})
}
-func (ms *MongoStorage) GetAlias(key string) (al *Alias, err error) {
+func (ms *MongoStorage) GetAlias(key string, skipCache bool) (al *Alias, err error) {
origKey := key
key = utils.ALIASES_PREFIX + key
- if x, ok := CacheGet(key); ok {
- if x != nil {
- al = &Alias{Values: x.(AliasValues)}
- al.SetId(origKey)
- return al, nil
+ if !skipCache {
+ if x, ok := cache2go.Get(key); ok {
+ if x != nil {
+ al = &Alias{Values: x.(AliasValues)}
+ al.SetId(origKey)
+ return al, nil
+ }
}
return nil, utils.ErrNotFound
}
@@ -881,12 +886,10 @@ func (ms *MongoStorage) GetAlias(key string) (al *Alias, err error) {
al = &Alias{Values: kv.Value}
al.SetId(origKey)
if err == nil {
- CacheSet(key, al.Values)
- // cache reverse alias
- al.SetReverseCache()
+ cache2go.Set(key, al.Values)
}
} else {
- CacheSet(key, nil)
+ cache2go.Set(key, nil)
}
return
}
@@ -899,12 +902,21 @@ func (ms *MongoStorage) SetAlias(al *Alias, cache bool) (err error) {
Value AliasValues
}{Key: al.GetId(), Value: al.Values})
if cache && err == nil {
- CacheSet(key, al.Values)
- al.SetReverseCache()
+ cache2go.Set(utils.ALIASES_PREFIX+al.GetId(), al.Values)
}
return err
}
+func (ms *MongoStorage) GetReverseAlias(reverseID string, skipCache bool) (ids []string, err error) {
+
+ return
+}
+
+func (ms *MongoStorage) SetReverseAlias(al *Alias, cache bool) (err error) {
+
+ return
+}
+
func (ms *MongoStorage) RemoveAlias(key string) (err error) {
al := &Alias{}
al.SetId(key)
@@ -921,26 +933,31 @@ func (ms *MongoStorage) RemoveAlias(key string) (err error) {
}
err = col.Remove(bson.M{"key": origKey})
if err == nil {
- al.RemoveReverseCache()
- CacheRemKey(key)
+ cache2go.RemKey(key)
}
return
}
+func (ms *MongoStorage) UpdateReverseAlias(oldAl, newAl *Alias) error {
+ return nil
+}
+
// Limit will only retrieve the last n items out of history, newest first
-func (ms *MongoStorage) GetLoadHistory(limit int) (loadInsts []*utils.LoadInstance, err error) {
+func (ms *MongoStorage) GetLoadHistory(limit int, skipCache bool) (loadInsts []*utils.LoadInstance, err error) {
if limit == 0 {
return nil, nil
}
- if x, ok := CacheGet(utils.LOADINST_KEY); ok {
- if x != nil {
- items := x.([]*utils.LoadInstance)
- if len(items) < limit || limit == -1 {
- return items, nil
+ if !skipCache {
+ if x, ok := cache2go.Get(utils.LOADINST_KEY); ok {
+ if x != nil {
+ items := x.([]*utils.LoadInstance)
+ if len(items) < limit || limit == -1 {
+ return items, nil
+ }
+ return items[:limit], nil
}
- return items[:limit], nil
+ return nil, utils.ErrNotFound
}
- return nil, utils.ErrNotFound
}
var kv struct {
Key string
@@ -951,8 +968,8 @@ func (ms *MongoStorage) GetLoadHistory(limit int) (loadInsts []*utils.LoadInstan
err = col.Find(bson.M{"key": utils.LOADINST_KEY}).One(&kv)
if err == nil {
loadInsts = kv.Value
- CacheRemKey(utils.LOADINST_KEY)
- CacheSet(utils.LOADINST_KEY, loadInsts)
+ cache2go.RemKey(utils.LOADINST_KEY)
+ cache2go.Set(utils.LOADINST_KEY, loadInsts)
}
if len(loadInsts) < limit || limit == -1 {
return loadInsts, nil
@@ -1004,17 +1021,19 @@ func (ms *MongoStorage) AddLoadHistory(ldInst *utils.LoadInstance, loadHistSize
}, 0, utils.LOADINST_KEY)
if cache && err == nil {
- CacheSet(utils.LOADINST_KEY, loadInsts)
+ cache2go.Set(utils.LOADINST_KEY, ldInst)
}
return err
}
-func (ms *MongoStorage) GetActionTriggers(key string) (atrs ActionTriggers, err error) {
- if x, ok := CacheGet(utils.ACTION_TRIGGER_PREFIX + key); ok {
- if x != nil {
- return x.(ActionTriggers), nil
+func (ms *MongoStorage) GetActionTriggers(key string, skipCache bool) (atrs ActionTriggers, err error) {
+ if !skipCache {
+ if x, ok := cache2go.Get(utils.ACTION_TRIGGER_PREFIX + key); ok {
+ if x != nil {
+ return x.(ActionTriggers), nil
+ }
+ return nil, utils.ErrNotFound
}
- return nil, utils.ErrNotFound
}
var kv struct {
@@ -1027,7 +1046,7 @@ func (ms *MongoStorage) GetActionTriggers(key string) (atrs ActionTriggers, err
if err == nil {
atrs = kv.Value
}
- CacheSet(utils.ACTION_TRIGGER_PREFIX+key, atrs)
+ cache2go.Set(utils.ACTION_TRIGGER_PREFIX+key, atrs)
return
}
@@ -1046,7 +1065,7 @@ func (ms *MongoStorage) SetActionTriggers(key string, atrs ActionTriggers, cache
Value ActionTriggers
}{Key: key, Value: atrs})
if cache && err == nil {
- CacheSet(utils.ACTION_TRIGGER_PREFIX+key, atrs)
+ cache2go.Set(utils.ACTION_TRIGGER_PREFIX+key, atrs)
}
return err
}
@@ -1056,17 +1075,19 @@ func (ms *MongoStorage) RemoveActionTriggers(key string) error {
defer session.Close()
err := col.Remove(bson.M{"key": key})
if err == nil {
- CacheRemKey(key)
+ cache2go.RemKey(key)
}
return err
}
-func (ms *MongoStorage) GetActionPlan(key string) (ats *ActionPlan, err error) {
- if x, ok := CacheGet(utils.ACTION_PLAN_PREFIX + key); ok {
- if x != nil {
- return x.(*ActionPlan), nil
+func (ms *MongoStorage) GetActionPlan(key string, skipCache bool) (ats *ActionPlan, err error) {
+ if !skipCache {
+ if x, ok := cache2go.Get(utils.ACTION_PLAN_PREFIX + key); ok {
+ if x != nil {
+ return x.(*ActionPlan), nil
+ }
+ return nil, utils.ErrNotFound
}
- return nil, utils.ErrNotFond
}
var kv struct {
Key string
@@ -1091,7 +1112,7 @@ func (ms *MongoStorage) GetActionPlan(key string) (ats *ActionPlan, err error) {
return nil, err
}
}
- CacheSet(utils.ACTION_PLAN_PREFIX+key, ats)
+ cache2go.Set(utils.ACTION_PLAN_PREFIX+key, ats)
return
}
@@ -1100,7 +1121,7 @@ func (ms *MongoStorage) SetActionPlan(key string, ats *ActionPlan, overwrite boo
defer session.Close()
// clean dots from account ids map
if len(ats.ActionTimings) == 0 {
- CacheRemKey(utils.ACTION_PLAN_PREFIX + key)
+ cache2go.RemKey(utils.ACTION_PLAN_PREFIX + key)
err := col.Remove(bson.M{"key": key})
if err != mgo.ErrNotFound {
return err
@@ -1131,13 +1152,13 @@ func (ms *MongoStorage) SetActionPlan(key string, ats *ActionPlan, overwrite boo
Value []byte
}{Key: key, Value: b.Bytes()})
if cache && err == nil {
- CacheSet(utils.ACTION_PLAN_PREFIX+key, at)
+ cache2go.Set(utils.ACTION_PLAN_PREFIX+key, ats)
}
return err
}
func (ms *MongoStorage) GetAllActionPlans() (ats map[string]*ActionPlan, err error) {
- apls, err := CacheGetAllEntries(utils.ACTION_PLAN_PREFIX)
+ apls, err := cache2go.GetAllEntries(utils.ACTION_PLAN_PREFIX)
if err != nil {
return nil, err
}
@@ -1174,12 +1195,14 @@ func (ms *MongoStorage) PopTask() (t *Task, err error) {
return
}
-func (ms *MongoStorage) GetDerivedChargers(key string) (dcs *utils.DerivedChargers, err error) {
- if x, ok := CacheGet(utils.DERIVEDCHARGERS_PREFIX + key); ok {
- if x != nil {
- return x.(*utils.DerivedChargers), nil
+func (ms *MongoStorage) GetDerivedChargers(key string, skipCache bool) (dcs *utils.DerivedChargers, err error) {
+ if !skipCache {
+ if x, ok := cache2go.Get(utils.DERIVEDCHARGERS_PREFIX + key); ok {
+ if x != nil {
+ return x.(*utils.DerivedChargers), nil
+ }
+ return nil, utils.ErrNotFound
}
- return nil, utils.ErrNotFound
}
var kv struct {
Key string
@@ -1191,13 +1214,13 @@ func (ms *MongoStorage) GetDerivedChargers(key string) (dcs *utils.DerivedCharge
if err == nil {
dcs = kv.Value
}
- CacheSet(utils.DERIVEDCHARGERS_PREFIX+key, dcs)
+ cache2go.Set(utils.DERIVEDCHARGERS_PREFIX+key, dcs)
return
}
func (ms *MongoStorage) SetDerivedChargers(key string, dcs *utils.DerivedChargers, cache bool) (err error) {
if dcs == nil || len(dcs.Chargers) == 0 {
- CacheRemKey(utils.DERIVEDCHARGERS_PREFIX + key)
+ cache2go.RemKey(utils.DERIVEDCHARGERS_PREFIX + key)
session, col := ms.conn(colDcs)
defer session.Close()
err = col.Remove(bson.M{"key": key})
@@ -1213,7 +1236,7 @@ func (ms *MongoStorage) SetDerivedChargers(key string, dcs *utils.DerivedCharger
Value *utils.DerivedChargers
}{Key: key, Value: dcs})
if cache && err == nil {
- CacheSet(utils.DERIVEDCHARGERS_PREFIX+key, dcs)
+ cache2go.Set(utils.DERIVEDCHARGERS_PREFIX+key, dcs)
}
return err
}
@@ -1274,7 +1297,7 @@ func (ms *MongoStorage) GetStructVersion() (rsv *StructVersion, err error) {
func (ms *MongoStorage) GetResourceLimit(id string, skipCache bool) (*ResourceLimit, error) {
return nil, nil
}
-func (ms *MongoStorage) SetResourceLimit(rl *ResourceLimit) error {
+func (ms *MongoStorage) SetResourceLimit(rl *ResourceLimit, cache bool) error {
return nil
}
func (ms *MongoStorage) RemoveResourceLimit(id string) error {
diff --git a/engine/storage_redis.go b/engine/storage_redis.go
index 88e92e565..afb51c333 100644
--- a/engine/storage_redis.go
+++ b/engine/storage_redis.go
@@ -24,7 +24,9 @@ import (
"errors"
"fmt"
"io/ioutil"
+ "strings"
+ "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
"github.com/mediocregopher/radix.v2/pool"
"github.com/mediocregopher/radix.v2/redis"
@@ -73,11 +75,6 @@ func NewRedisStorage(address string, db int, pass, mrshlerStr string, maxConns i
} else {
return nil, fmt.Errorf("Unsupported marshaler: %v", mrshlerStr)
}
- if cacheDumpDir != "" {
- if err := CacheSetDumperPath(cacheDumpDir); err != nil {
- utils.Logger.Info(" init error: " + err.Error())
- }
- }
return &RedisStorage{db: p, ms: mrshler, cacheDumpDir: cacheDumpDir, loadHistorySize: loadHistorySize}, nil
}
@@ -89,19 +86,107 @@ func (rs *RedisStorage) Flush(ignore string) error {
return rs.db.Cmd("FLUSHDB").Err
}
-func (rs *RedisStorage) GetKeysForPrefix(prefix string) ([]string, error) {
- if x, ok := CacheGet(utils.GENERIC_PREFIX + "keys_" + prefix); ok {
- if x != nil {
- return x.([]string), nil
- }
- return nil, utils.ErrNotFound
+func (rs *RedisStorage) PreloadRatingCache() error {
+ err := rs.PreloadCacheForPrefix(utils.RATING_PLAN_PREFIX)
+ if err != nil {
+ return err
}
+ // add more prefixes if needed
+ return nil
+}
+
+func (rs *RedisStorage) PreloadAccountingCache() error {
+ err := rs.PreloadCacheForPrefix(utils.RATING_PLAN_PREFIX)
+ if err != nil {
+ return err
+ }
+ // add more prefixes if needed
+ return nil
+}
+
+func (rs *RedisStorage) PreloadCacheForPrefix(prefix string) error {
+ cache2go.BeginTransaction()
+ cache2go.RemPrefixKey(prefix)
+ keyList, err := rs.GetKeysForPrefix(prefix)
+ if err != nil {
+ cache2go.RollbackTransaction()
+ return err
+ }
+ switch prefix {
+ case utils.RATING_PLAN_PREFIX:
+ for _, key := range keyList {
+ _, err := rs.GetRatingPlan(key[len(utils.RATING_PLAN_PREFIX):], true)
+ if err != nil {
+ cache2go.RollbackTransaction()
+ return err
+ }
+ }
+ default:
+ return utils.ErrInvalidKey
+ }
+ cache2go.CommitTransaction()
+ return nil
+}
+
+func (rs *RedisStorage) RebuildReverseForPrefix(prefix string) error {
+ err := rs.db.Cmd("MULTI").Err
+ if err != nil {
+ return err
+ }
+ keys, err := rs.GetKeysForPrefix(prefix)
+ if err != nil {
+ return err
+ }
+ for _, key := range keys {
+ err = rs.db.Cmd("DEL", key).Err
+ if err != nil {
+ return err
+ }
+ }
+ switch prefix {
+ case utils.REVERSE_DESTINATION_PREFIX:
+ keys, err = rs.GetKeysForPrefix(utils.DESTINATION_PREFIX)
+ if err != nil {
+ return err
+ }
+ for _, key := range keys {
+ dest, err := rs.GetDestination(key[len(utils.DESTINATION_PREFIX):])
+ if err != nil {
+ return err
+ }
+ if err := rs.SetReverseDestination(dest, false); err != nil {
+ return err
+ }
+ }
+ case utils.REVERSE_ALIASES_PREFIX:
+ keys, err = rs.GetKeysForPrefix(utils.ALIASES_PREFIX)
+ if err != nil {
+ return err
+ }
+ for _, key := range keys {
+ al, err := rs.GetAlias(key[len(utils.ALIASES_PREFIX):], false)
+ if err != nil {
+ return err
+ }
+ if err := rs.SetReverseAlias(al, false); err != nil {
+ return err
+ }
+ }
+ default:
+ return utils.ErrInvalidKey
+ }
+ err = rs.db.Cmd("EXEC").Err
+ if err != nil {
+ return err
+ }
+ return nil
+}
+
+func (rs *RedisStorage) GetKeysForPrefix(prefix string) ([]string, error) {
r := rs.db.Cmd("KEYS", prefix+"*")
if r.Err != nil {
- CacheSet(utils.GENERIC_PREFIX+"keys_"+prefix, nil)
return nil, r.Err
}
- CacheSet(utils.GENERIC_PREFIX+"keys_"+prefix, r.List())
return r.List()
}
@@ -109,25 +194,22 @@ func (rs *RedisStorage) GetKeysForPrefix(prefix string) ([]string, error) {
func (rs *RedisStorage) HasData(category, subject string) (bool, error) {
switch category {
case utils.DESTINATION_PREFIX, utils.RATING_PLAN_PREFIX, utils.RATING_PROFILE_PREFIX, utils.ACTION_PREFIX, utils.ACTION_PLAN_PREFIX, utils.ACCOUNT_PREFIX, utils.DERIVEDCHARGERS_PREFIX:
- if x, ok := CacheGet(utils.GENERIC_PREFIX + "has_" + category + "_" + subject); ok {
- return x.(bool), nil
- }
i, err := rs.db.Cmd("EXISTS", category+subject).Int()
- CacheSet(utils.GENERIC_PREFIX+"has_"+category+"_"+subject, i == 1)
return i == 1, err
}
- CacheSet(utils.GENERIC_PREFIX+"has_"+category+"_"+subject, false)
return false, errors.New("unsupported HasData category")
}
-func (rs *RedisStorage) GetRatingPlan(key string) (rp *RatingPlan, err error) {
+func (rs *RedisStorage) GetRatingPlan(key string, skipCache bool) (rp *RatingPlan, err error) {
key = utils.RATING_PLAN_PREFIX + key
- if x, ok := CacheGet(key); ok {
- if x != nil {
- return x.(*RatingPlan), nil
+ if !skipCache {
+ if x, ok := cache2go.Get(key); ok {
+ if x != nil {
+ return x.(*RatingPlan), nil
+ }
+ return nil, utils.ErrNotFound
}
- return nil, utils.ErrNotFound
}
var values []byte
if values, err = rs.db.Cmd("GET", key).Bytes(); err == nil {
@@ -144,7 +226,7 @@ func (rs *RedisStorage) GetRatingPlan(key string) (rp *RatingPlan, err error) {
rp = new(RatingPlan)
err = rs.ms.Unmarshal(out, rp)
}
- CacheSet(key, rp)
+ cache2go.Set(key, rp)
return
}
@@ -160,26 +242,28 @@ func (rs *RedisStorage) SetRatingPlan(rp *RatingPlan, cache bool) (err error) {
go historyScribe.Call("HistoryV1.Record", rp.GetHistoryRecord(), &response)
}
if cache && err == nil {
- CacheSet(utils.RATING_PLAN_PREFIX+rp.Id, rp)
+ cache2go.Set(utils.RATING_PLAN_PREFIX+rp.Id, rp)
}
return
}
-func (rs *RedisStorage) GetRatingProfile(key string) (rpf *RatingProfile, err error) {
+func (rs *RedisStorage) GetRatingProfile(key string, skipCache bool) (rpf *RatingProfile, err error) {
key = utils.RATING_PROFILE_PREFIX + key
- if x, ok := CacheGet(key); ok {
- if x != nil {
- return x.(*RatingProfile), nil
+ if !skipCache {
+ if x, ok := cache2go.Get(key); ok {
+ if x != nil {
+ return x.(*RatingProfile), nil
+ }
+ return nil, utils.ErrNotFound
}
- return nil, utils.ErrNotFound
}
var values []byte
if values, err = rs.db.Cmd("GET", key).Bytes(); err == nil {
rpf = new(RatingProfile)
err = rs.ms.Unmarshal(values, rpf)
}
- CacheSet(key, rpf)
+ cache2go.Set(key, rpf)
return
}
@@ -191,7 +275,7 @@ func (rs *RedisStorage) SetRatingProfile(rpf *RatingProfile, cache bool) (err er
go historyScribe.Call("HistoryV1.Record", rpf.GetHistoryRecord(false), &response)
}
if cache && err == nil {
- CacheSet(utils.RATING_PROFILE_PREFIX+rpf.Id, rpf)
+ cache2go.Set(utils.RATING_PROFILE_PREFIX+rpf.Id, rpf)
}
return
}
@@ -210,7 +294,7 @@ func (rs *RedisStorage) RemoveRatingProfile(key string) error {
if err = conn.Cmd("DEL", key).Err; err != nil {
return err
}
- CacheRemKey(key)
+ cache2go.RemKey(key)
rpf := &RatingProfile{Id: key}
if historyScribe != nil {
response := 0
@@ -220,19 +304,21 @@ func (rs *RedisStorage) RemoveRatingProfile(key string) error {
return nil
}
-func (rs *RedisStorage) GetLCR(key string) (lcr *LCR, err error) {
+func (rs *RedisStorage) GetLCR(key string, skipCache bool) (lcr *LCR, err error) {
key = utils.LCR_PREFIX + key
- if x, ok := CacheGet(key); ok {
- if x != nil {
- return x.(*LCR), nil
+ if !skipCache {
+ if x, ok := cache2go.Get(key); ok {
+ if x != nil {
+ return x.(*LCR), nil
+ }
+ return nil, utils.ErrNotFound
}
- return nil, utils.ErrNotFound
}
var values []byte
if values, err = rs.db.Cmd("GET", key).Bytes(); err == nil {
err = rs.ms.Unmarshal(values, &lcr)
}
- CacheSet(key, lcr)
+ cache2go.Set(key, lcr)
return
}
@@ -240,10 +326,11 @@ func (rs *RedisStorage) SetLCR(lcr *LCR, cache bool) (err error) {
result, err := rs.ms.Marshal(lcr)
err = rs.db.Cmd("SET", utils.LCR_PREFIX+lcr.GetId(), result).Err
if cache && err == nil {
- CacheSet(utils.LCR_PREFIX+lcr.GetId(), lcr)
+ cache2go.Set(utils.LCR_PREFIX+lcr.GetId(), lcr)
}
return
}
+
func (rs *RedisStorage) GetDestination(key string) (dest *Destination, err error) {
key = utils.DESTINATION_PREFIX + key
var values []byte
@@ -260,17 +347,13 @@ func (rs *RedisStorage) GetDestination(key string) (dest *Destination, err error
r.Close()
dest = new(Destination)
err = rs.ms.Unmarshal(out, dest)
- // create optimized structure
- for _, p := range dest.Prefixes {
- CachePush(utils.DESTINATION_PREFIX+p, dest.Id)
- }
} else {
return nil, utils.ErrNotFound
}
return
}
-func (rs *RedisStorage) SetDestination(dest *Destination, cache bool) (err error) {
+func (rs *RedisStorage) SetDestination(dest *Destination) (err error) {
result, err := rs.ms.Marshal(dest)
if err != nil {
return err
@@ -284,19 +367,18 @@ func (rs *RedisStorage) SetDestination(dest *Destination, cache bool) (err error
response := 0
go historyScribe.Call("HistoryV1.Record", dest.GetHistoryRecord(false), &response)
}
- if cache && err == nil {
- CacheSet(utils.DESTINATION_PREFIX+dest.Id, dest)
- }
return
}
-func (rs *RedisStorage) GetReverseDestination(prefix string) (ids []string, err error) {
+func (rs *RedisStorage) GetReverseDestination(prefix string, skipCache bool) (ids []string, err error) {
prefix = utils.REVERSE_DESTINATION_PREFIX + prefix
- if x, ok := CacheGet(prefix); ok {
- if x != nil {
- return x.([]string), nil
+ if !skipCache {
+ if x, ok := cache2go.Get(prefix); ok {
+ if x != nil {
+ return x.([]string), nil
+ }
+ return nil, utils.ErrNotFound
}
- return nil, utils.ErrNotFound
}
var values []string
if values, err = rs.db.Cmd("SMEMBERS", prefix).List(); len(values) > 0 && err == nil {
@@ -304,91 +386,114 @@ func (rs *RedisStorage) GetReverseDestination(prefix string) (ids []string, err
return nil, utils.ErrNotFound
}
- CacheSet(prefix, values)
+ cache2go.Set(prefix, values)
return
}
func (rs *RedisStorage) SetReverseDestination(dest *Destination, cache bool) (err error) {
for _, p := range dest.Prefixes {
- err = rs.db.Cmd("SADD", utils.REVERSE_DESTINATION_PREFIX+p, dest.Id).Err
+ key := utils.REVERSE_DESTINATION_PREFIX + p
+ err = rs.db.Cmd("SADD", key, dest.Id).Err
if err != nil {
break
}
- }
- if cache && err == nil {
- CacheSet(utils.REVERSE_DESTINATION_PREFIX+dest.Id, dest)
+ if cache && err == nil {
+ _, err = rs.GetReverseDestination(p, true) // will recache
+ }
}
return
}
func (rs *RedisStorage) RemoveDestination(destID string) (err error) {
- /*conn, err := rs.db.Get()
+ key := utils.DESTINATION_PREFIX + destID
+ // get destination for prefix list
+ d, err := rs.GetDestination(destID)
+ if err != nil {
+ return
+ }
+ err = rs.db.Cmd("DEL", key).Err
if err != nil {
return err
}
- var dest *Destination
- defer rs.db.Put(conn)
- if values, err = conn.Cmd("GET", key).Bytes(); len(values) > 0 && err == nil {
- b := bytes.NewBuffer(values)
- r, err := zlib.NewReader(b)
+ cache2go.RemKey(key)
+ for _, prefix := range d.Prefixes {
+ err = rs.db.Cmd("SREM", utils.REVERSE_DESTINATION_PREFIX+prefix, destID).Err
if err != nil {
return err
}
- out, err := ioutil.ReadAll(r)
+ _, err = rs.GetReverseDestination(prefix, true) // it will recache the destination
if err != nil {
return err
}
- r.Close()
- dest = new(Destination)
- err = rs.ms.Unmarshal(out, dest)
- } else {
- return utils.ErrNotFound
}
- key := utils.DESTINATION_PREFIX + destID
- if err = conn.Cmd("DEL", key).Err; err != nil {
- return err
- }
- if dest != nil {
- for _, prefix := range dest.Prefixes {
- changed := false
- if idIDs, err := CacheGet(utils.DESTINATION_PREFIX + prefix); err == nil {
- dIDs := idIDs.(map[interface{}]struct{})
- if len(dIDs) == 1 {
- // remove de prefix from cache
- CacheRemKey(utils.DESTINATION_PREFIX + prefix)
- } else {
- // delete the destination from list and put the new list in chache
- delete(dIDs, searchedDID)
- changed = true
- }
- }
- if changed {
- CacheSet(utils.DESTINATION_PREFIX+prefix, dIDs)
- }
- }
- }
- dest := &Destination{Id: key}
- if historyScribe != nil {
- response := 0
- go historyScribe.Call("HistoryV1.Record", dest.GetHistoryRecord(true), &response)
- }*/
-
return
}
-func (rs *RedisStorage) GetActions(key string) (as Actions, err error) {
- key = utils.ACTION_PREFIX + key
- if x, ok := CacheGet(key); ok {
- if x != nil {
- return x.(Actions), nil
+func (rs *RedisStorage) UpdateReverseDestination(oldDest, newDest *Destination) error {
+ var obsoletePrefixes []string
+ var addedPrefixes []string
+ var found bool
+ for _, oldPrefix := range oldDest.Prefixes {
+ found = false
+ for _, newPrefix := range newDest.Prefixes {
+ if oldPrefix == newPrefix {
+ found = true
+ break
+ }
+ }
+ if !found {
+ obsoletePrefixes = append(obsoletePrefixes, oldPrefix)
+ }
+ }
+
+ for _, newPrefix := range newDest.Prefixes {
+ found = false
+ for _, oldPrefix := range oldDest.Prefixes {
+ if newPrefix == oldPrefix {
+ found = true
+ break
+ }
+ }
+ if !found {
+ addedPrefixes = append(addedPrefixes, newPrefix)
+ }
+ }
+
+ // remove id for all obsolete prefixes
+ var err error
+ for _, obsoletePrefix := range obsoletePrefixes {
+ err = rs.db.Cmd("SREM", utils.REVERSE_DESTINATION_PREFIX+obsoletePrefix, oldDest.Id).Err
+ if err != nil {
+ return err
+ }
+ cache2go.RemKey(utils.REVERSE_DESTINATION_PREFIX + obsoletePrefix)
+ }
+
+ // add the id to all new prefixes
+ for _, addedPrefix := range addedPrefixes {
+ err = rs.db.Cmd("SADD", utils.REVERSE_ALIASES_PREFIX, addedPrefix, oldDest.Id).Err
+ if err != nil {
+ return err
+ }
+ }
+ return nil
+}
+
+func (rs *RedisStorage) GetActions(key string, skipCache bool) (as Actions, err error) {
+ key = utils.ACTION_PREFIX + key
+ if !skipCache {
+ if x, ok := cache2go.Get(key); ok {
+ if x != nil {
+ return x.(Actions), nil
+ }
+ return nil, utils.ErrNotFound
}
- return nil, utils.ErrNotFound
}
var values []byte
if values, err = rs.db.Cmd("GET", key).Bytes(); err == nil {
err = rs.ms.Unmarshal(values, &as)
}
- CacheSet(key, as)
+ cache2go.Set(key, as)
return
}
@@ -396,30 +501,32 @@ func (rs *RedisStorage) SetActions(key string, as Actions, cache bool) (err erro
result, err := rs.ms.Marshal(&as)
err = rs.db.Cmd("SET", utils.ACTION_PREFIX+key, result).Err
if cache && err == nil {
- CacheSet(utils.ACTION_PREFIX+key, as)
+ cache2go.Set(utils.ACTION_PREFIX+key, as)
}
return
}
func (rs *RedisStorage) RemoveActions(key string) (err error) {
err = rs.db.Cmd("DEL", utils.ACTION_PREFIX+key).Err
- CacheRemKey(utils.ACTION_PREFIX + key)
+ cache2go.RemKey(utils.ACTION_PREFIX + key)
return
}
-func (rs *RedisStorage) GetSharedGroup(key string) (sg *SharedGroup, err error) {
+func (rs *RedisStorage) GetSharedGroup(key string, skipCache bool) (sg *SharedGroup, err error) {
key = utils.SHARED_GROUP_PREFIX + key
- if x, ok := CacheGet(key); ok {
- if x != nil {
- return x.(*SharedGroup), nil
+ if !skipCache {
+ if x, ok := cache2go.Get(key); ok {
+ if x != nil {
+ return x.(*SharedGroup), nil
+ }
+ return nil, utils.ErrNotFound
}
- return nil, utils.ErrNotFound
}
var values []byte
if values, err = rs.db.Cmd("GET", key).Bytes(); err == nil {
err = rs.ms.Unmarshal(values, &sg)
}
- CacheSet(key, sg)
+ cache2go.Set(key, sg)
return
}
@@ -427,7 +534,7 @@ func (rs *RedisStorage) SetSharedGroup(sg *SharedGroup, cache bool) (err error)
result, err := rs.ms.Marshal(sg)
err = rs.db.Cmd("SET", utils.SHARED_GROUP_PREFIX+sg.Id, result).Err
if cache && err == nil {
- CacheSet(utils.SHARED_GROUP_PREFIX+sg.Id, sg)
+ cache2go.Set(utils.SHARED_GROUP_PREFIX+sg.Id, sg)
}
return
}
@@ -567,17 +674,19 @@ func (rs *RedisStorage) RemoveUser(key string) (err error) {
return rs.db.Cmd("DEL", utils.USERS_PREFIX+key).Err
}
-func (rs *RedisStorage) GetAlias(key string) (al *Alias, err error) {
+func (rs *RedisStorage) GetAlias(key string, skipCache bool) (al *Alias, err error) {
origKey := key
key = utils.ALIASES_PREFIX + key
- if x, ok := CacheGet(key); ok {
- if x != nil {
- al = &Alias{Values: x.(AliasValues)}
- al.SetId(origKey)
- return al, nil
+ if !skipCache {
+ if x, ok := cache2go.Get(key); ok {
+ if x != nil {
+ al = &Alias{Values: x.(AliasValues)}
+ al.SetId(origKey)
+ return al, nil
+ }
+ return nil, utils.ErrNotFound
}
- return nil, utils.ErrNotFound
}
var values []byte
if values, err = rs.db.Cmd("GET", key).Bytes(); err == nil {
@@ -585,12 +694,10 @@ func (rs *RedisStorage) GetAlias(key string) (al *Alias, err error) {
al.SetId(origKey)
err = rs.ms.Unmarshal(values, &al.Values)
if err == nil {
- CacheSet(key, al.Values)
- // cache reverse alias
- al.SetReverseCache()
+ cache2go.Set(key, al.Values)
}
} else {
- CacheSet(key, nil)
+ cache2go.Set(key, nil)
}
return
}
@@ -600,58 +707,162 @@ func (rs *RedisStorage) SetAlias(al *Alias, cache bool) (err error) {
if err != nil {
return err
}
- err = rs.db.Cmd("SET", utils.ALIASES_PREFIX+al.GetId(), result).Err
+ key := utils.ALIASES_PREFIX + al.GetId()
+ err = rs.db.Cmd("SET", key, result).Err
if cache && err == nil {
- CacheSet(key, al.Values)
- al.SetReverseCache()
+ cache2go.Set(key, al.Values)
}
return
}
-func (rs *RedisStorage) RemoveAlias(key string) (err error) {
- conn, err := rs.db.Get()
+func (rs *RedisStorage) GetReverseAlias(reverseID string, skipCache bool) (ids []string, err error) {
+ key := utils.REVERSE_ALIASES_PREFIX + reverseID
+ if !skipCache {
+ if x, ok := cache2go.Get(key); ok {
+ if x != nil {
+ return x.([]string), nil
+ }
+ return nil, utils.ErrNotFound
+ }
+ }
+ var values []string
+ if values, err = rs.db.Cmd("SMEMBERS", key).List(); len(values) > 0 && err == nil {
+ } else {
+ return nil, utils.ErrNotFound
+ }
+ cache2go.Set(key, values)
+ return
+}
+
+func (rs *RedisStorage) SetReverseAlias(al *Alias, cache bool) (err error) {
+ for _, value := range al.Values {
+ for target, pairs := range value.Pairs {
+ for _, alias := range pairs {
+ rKey := strings.Join([]string{utils.REVERSE_ALIASES_PREFIX, alias, target, al.Context}, "")
+ id := utils.ConcatenatedKey(al.GetId(), value.DestinationId)
+ err = rs.db.Cmd("SADD", rKey, id).Err
+ if err != nil {
+ break
+ }
+ if cache && err == nil {
+ // remove previos cache
+ cache2go.RemKey(rKey)
+ _, err = rs.GetReverseAlias(id, true) // will recache
+ }
+ }
+ }
+ }
+
+ return
+}
+
+func (rs *RedisStorage) RemoveAlias(id string) (err error) {
+ key := utils.ALIASES_PREFIX + id
+ // get alias for values list
+ al, err := rs.GetAlias(id, false)
+ if err != nil {
+ return
+ }
+ err = rs.db.Cmd("DEL", key).Err
if err != nil {
return err
}
- defer rs.db.Put(conn)
- al := &Alias{}
- al.SetId(key)
- key = utils.ALIASES_PREFIX + key
- aliasValues := make(AliasValues, 0)
- if values, err := conn.Cmd("GET", key).Bytes(); err == nil {
- rs.ms.Unmarshal(values, &aliasValues)
- }
- al.Values = aliasValues
- err = conn.Cmd("DEL", key).Err
- if err == nil {
- al.RemoveReverseCache()
- CacheRemKey(key)
+ cache2go.RemKey(key)
+
+ for _, value := range al.Values {
+ tmpKey := utils.ConcatenatedKey(al.GetId(), value.DestinationId)
+ for target, pairs := range value.Pairs {
+ for _, alias := range pairs {
+ rKey := utils.REVERSE_ALIASES_PREFIX + alias + target + al.Context
+ err = rs.db.Cmd("SREM", rKey, tmpKey).Err
+ if err != nil {
+ return err
+ }
+ cache2go.RemKey(rKey)
+ _, err = rs.GetReverseAlias(rKey, true) // recache
+ if err != nil {
+ return err
+ }
+ }
+ }
}
return
}
+func (rs *RedisStorage) UpdateReverseAlias(oldAl, newAl *Alias) error {
+ /*var obsoleteDestinations []string
+ var addedDestinations []string
+ var found bool
+ for _, oldValue := range oldAl.Values {
+ found = false
+ for _, newPrefix := range newDest.Destinations {
+ if oldPrefix == newPrefix {
+ found = true
+ break
+ }
+ }
+ if !found {
+ obsoleteDestinations = append(obsoleteDestinations, oldPrefix)
+ }
+ }
+
+ for _, newPrefix := range newDest.Destinations {
+ found = false
+ for _, oldPrefix := range oldDest.Destinations {
+ if newPrefix == oldPrefix {
+ found = true
+ break
+ }
+ }
+ if !found {
+ addedDestinations = append(addedDestinations, newPrefix)
+ }
+ }
+
+ // remove id for all obsolete prefixes
+ var err error
+ for _, obsoletePrefix := range obsoleteDestinations {
+ err = rs.db.Cmd("SREM", utils.REVERSE_DESTINATION_PREFIX+obsoletePrefix, oldDest.Id).Err
+ if err != nil {
+ return err
+ }
+ cache2go.RemKey(utils.REVERSE_DESTINATION_PREFIX + obsoletePrefix)
+ }
+
+ // add the id to all new prefixes
+ for _, addedPrefix := range addedDestinations {
+ err = rs.db.Cmd("SADD", utils.REVERSE_ALIASES_PREFIX, addedPrefix, oldDest.Id).Err
+ if err != nil {
+ return err
+ }
+ }*/
+ return nil
+}
+
// Limit will only retrieve the last n items out of history, newest first
-func (rs *RedisStorage) GetLoadHistory(limit int) ([]*utils.LoadInstance, error) {
+func (rs *RedisStorage) GetLoadHistory(limit int, skipCache bool) ([]*utils.LoadInstance, error) {
if limit == 0 {
return nil, nil
}
- if x, ok := CacheGet(utils.LOADINST_KEY); ok {
- if x != nil {
- items := x.([]*utils.LoadInstance)
- if len(items) < limit || limit == -1 {
- return items, nil
+ if !skipCache {
+ if x, ok := cache2go.Get(utils.LOADINST_KEY); ok {
+ if x != nil {
+ items := x.([]*utils.LoadInstance)
+ if len(items) < limit || limit == -1 {
+ return items, nil
+ }
+ return items[:limit], nil
}
- return items[:limit], nil
+ return nil, utils.ErrNotFound
}
- return nil, utils.ErrNotFound
}
if limit != -1 {
limit -= -1 // Decrease limit to match redis approach on lrange
}
marshaleds, err := rs.db.Cmd("LRANGE", utils.LOADINST_KEY, 0, limit).ListBytes()
if err != nil {
- CacheSet(utils.LOADINST_KEY, nil)
+ cache2go.Set(utils.LOADINST_KEY, nil)
return nil, err
}
loadInsts := make([]*utils.LoadInstance, len(marshaleds))
@@ -663,8 +874,8 @@ func (rs *RedisStorage) GetLoadHistory(limit int) ([]*utils.LoadInstance, error)
}
loadInsts[idx] = &lInst
}
- CacheRemKey(utils.LOADINST_KEY)
- CacheSet(utils.LOADINST_KEY, loadInsts)
+ cache2go.RemKey(utils.LOADINST_KEY)
+ cache2go.Set(utils.LOADINST_KEY, loadInsts)
if len(loadInsts) < limit || limit == -1 {
return loadInsts, nil
}
@@ -700,24 +911,26 @@ func (rs *RedisStorage) AddLoadHistory(ldInst *utils.LoadInstance, loadHistSize
}, 0, utils.LOADINST_KEY)
if cache && err == nil {
- CacheSet(utils.LOADINST_KEY, loadInsts)
+ cache2go.Set(utils.LOADINST_KEY, ldInst)
}
return err
}
-func (rs *RedisStorage) GetActionTriggers(key string) (atrs ActionTriggers, err error) {
+func (rs *RedisStorage) GetActionTriggers(key string, skipCache bool) (atrs ActionTriggers, err error) {
key = utils.ACTION_TRIGGER_PREFIX + key
- if x, ok := CacheGet(key); ok {
- if x != nil {
- return x.(ActionTriggers), nil
+ if !skipCache {
+ if x, ok := cache2go.Get(key); ok {
+ if x != nil {
+ return x.(ActionTriggers), nil
+ }
+ return nil, utils.ErrNotFound
}
- return nil, utils.ErrNotFound
}
var values []byte
if values, err = rs.db.Cmd("GET", key).Bytes(); err == nil {
err = rs.ms.Unmarshal(values, &atrs)
}
- CacheSet(key, atrs)
+ cache2go.Set(key, atrs)
return
}
@@ -737,7 +950,7 @@ func (rs *RedisStorage) SetActionTriggers(key string, atrs ActionTriggers, cache
}
err = conn.Cmd("SET", utils.ACTION_TRIGGER_PREFIX+key, result).Err
if cache && err == nil {
- CacheSet(utils.ACTION_TRIGGER_PREFIX+key, atrs)
+ cache2go.Set(utils.ACTION_TRIGGER_PREFIX+key, atrs)
}
return
}
@@ -746,19 +959,21 @@ func (rs *RedisStorage) RemoveActionTriggers(key string) (err error) {
key = utils.ACTION_TRIGGER_PREFIX + key
err = rs.db.Cmd("DEL", key).Err
if err == nil {
- CacheRemKey(key)
+ cache2go.RemKey(key)
}
return
}
-func (rs *RedisStorage) GetActionPlan(key string) (ats *ActionPlan, err error) {
+func (rs *RedisStorage) GetActionPlan(key string, skipCache bool) (ats *ActionPlan, err error) {
key = utils.ACTION_PLAN_PREFIX + key
- if x, ok := CacheGet(key); ok {
- if x != nil {
- return x.(*ActionPlan), nil
+ if !skipCache {
+ if x, ok := cache2go.Get(key); ok {
+ if x != nil {
+ return x.(*ActionPlan), nil
+ }
+ return nil, utils.ErrNotFound
}
- return nil, utils.ErrNotFond
}
var values []byte
if values, err = rs.db.Cmd("GET", key).Bytes(); err == nil {
@@ -774,7 +989,7 @@ func (rs *RedisStorage) GetActionPlan(key string) (ats *ActionPlan, err error) {
r.Close()
err = rs.ms.Unmarshal(out, &ats)
}
- CacheSet(key, ats)
+ cache2go.Set(key, ats)
return
}
@@ -782,7 +997,7 @@ func (rs *RedisStorage) SetActionPlan(key string, ats *ActionPlan, overwrite, ca
if len(ats.ActionTimings) == 0 {
// delete the key
err = rs.db.Cmd("DEL", utils.ACTION_PLAN_PREFIX+key).Err
- CacheRemKey(utils.ACTION_PLAN_PREFIX + key)
+ cache2go.RemKey(utils.ACTION_PLAN_PREFIX + key)
return err
}
if !overwrite {
@@ -807,13 +1022,13 @@ func (rs *RedisStorage) SetActionPlan(key string, ats *ActionPlan, overwrite, ca
w.Close()
err = rs.db.Cmd("SET", utils.ACTION_PLAN_PREFIX+key, b.Bytes()).Err
if cache && err == nil {
- CacheSet(utils.ACTION_PLAN_PREFIX+key, at)
+ cache2go.Set(utils.ACTION_PLAN_PREFIX+key, ats)
}
return
}
func (rs *RedisStorage) GetAllActionPlans() (ats map[string]*ActionPlan, err error) {
- apls, err := CacheGetAllEntries(utils.ACTION_PLAN_PREFIX)
+ apls, err := cache2go.GetAllEntries(utils.ACTION_PLAN_PREFIX)
if err != nil {
return nil, err
}
@@ -844,19 +1059,21 @@ func (rs *RedisStorage) PopTask() (t *Task, err error) {
return
}
-func (rs *RedisStorage) GetDerivedChargers(key string) (dcs *utils.DerivedChargers, err error) {
+func (rs *RedisStorage) GetDerivedChargers(key string, skipCache bool) (dcs *utils.DerivedChargers, err error) {
key = utils.DERIVEDCHARGERS_PREFIX + key
- if x, ok := CacheGet(key); ok {
- if x != nil {
- return x.(*utils.DerivedChargers), nil
+ if !skipCache {
+ if x, ok := cache2go.Get(key); ok {
+ if x != nil {
+ return x.(*utils.DerivedChargers), nil
+ }
+ return nil, utils.ErrNotFound
}
- return nil, utils.ErrNotFound
}
var values []byte
if values, err = rs.db.Cmd("GET", key).Bytes(); err == nil {
err = rs.ms.Unmarshal(values, &dcs)
}
- CacheSet(key, dcs)
+ cache2go.Set(key, dcs)
return dcs, err
}
@@ -864,7 +1081,7 @@ func (rs *RedisStorage) SetDerivedChargers(key string, dcs *utils.DerivedCharger
key = utils.DERIVEDCHARGERS_PREFIX + key
if dcs == nil || len(dcs.Chargers) == 0 {
err = rs.db.Cmd("DEL").Err
- CacheRemKey(key)
+ cache2go.RemKey(key)
return err
}
marshaled, err := rs.ms.Marshal(dcs)
@@ -873,7 +1090,7 @@ func (rs *RedisStorage) SetDerivedChargers(key string, dcs *utils.DerivedCharger
}
err = rs.db.Cmd("SET", key, marshaled).Err
if cache && err == nil {
- CacheSet(key, dcs)
+ cache2go.Set(key, dcs)
}
return
}
@@ -936,11 +1153,13 @@ func (rs *RedisStorage) GetStructVersion() (rsv *StructVersion, err error) {
func (rs *RedisStorage) GetResourceLimit(id string, skipCache bool) (rl *ResourceLimit, err error) {
key := utils.ResourceLimitsPrefix + id
+
if !skipCache {
- if x, err := CacheGet(key); err == nil {
- return x.(*ResourceLimit), nil
- } else {
- return nil, err
+ if x, ok := cache2go.Get(key); ok {
+ if x != nil {
+ return x.(*ResourceLimit), nil
+ }
+ return nil, utils.ErrNotFound
}
}
var values []byte
@@ -951,18 +1170,19 @@ func (rs *RedisStorage) GetResourceLimit(id string, skipCache bool) (rl *Resourc
return nil, err
}
}
- CacheSet(key, rl)
+
+ cache2go.Set(key, rl)
}
return
}
-func (rs *RedisStorage) SetResourceLimit(rl *ResourceLimit) error {
+func (rs *RedisStorage) SetResourceLimit(rl *ResourceLimit, cache bool) error {
result, err := rs.ms.Marshal(rl)
if err != nil {
return err
}
key := utils.ResourceLimitsPrefix + rl.ID
err = rs.db.Cmd("SET", key, result).Err
- //CacheSet(key, rl)
+ //cache2go.Set(key, rl)
return err
}
func (rs *RedisStorage) RemoveResourceLimit(id string) error {
@@ -970,6 +1190,6 @@ func (rs *RedisStorage) RemoveResourceLimit(id string) error {
if err := rs.db.Cmd("DEL", key).Err; err != nil {
return err
}
- CacheRemKey(key)
+ cache2go.RemKey(key)
return nil
}
diff --git a/engine/storage_redis_local_test.go b/engine/storage_redis_local_test.go
index 7e4893992..b7f1c9ea6 100644
--- a/engine/storage_redis_local_test.go
+++ b/engine/storage_redis_local_test.go
@@ -48,7 +48,7 @@ func TestFlush(t *testing.T) {
if err := rds.Flush(""); err != nil {
t.Error("Failed to Flush redis database", err.Error())
}
- rds.CacheRatingAll("TestConnectRedis")
+ rds.PreloadRatingCache()
}
func TestSetGetDerivedCharges(t *testing.T) {
@@ -62,7 +62,7 @@ func TestSetGetDerivedCharges(t *testing.T) {
&utils.DerivedCharger{RunID: "extra2", RequestTypeField: "*default", DirectionField: "*default", TenantField: "*default", CategoryField: "*default",
AccountField: "ivo", SubjectField: "ivo", DestinationField: "*default", SetupTimeField: "*default", AnswerTimeField: "*default", UsageField: "*default"},
}}
- if err := rds.SetDerivedChargers(keyCharger1, charger1); err != nil {
+ if err := rds.SetDerivedChargers(keyCharger1, charger1, true); err != nil {
t.Error("Error on setting DerivedChargers", err.Error())
}
// Try retrieving from cache, should not be in yet
diff --git a/engine/storage_sql.go b/engine/storage_sql.go
index e8fce7e51..f1769bff7 100644
--- a/engine/storage_sql.go
+++ b/engine/storage_sql.go
@@ -54,10 +54,18 @@ func (self *SQLStorage) Flush(scriptsPath string) (err error) {
return nil
}
-func (self *SQLStorage) GetKeysForPrefix(prefix string, skipCache bool) ([]string, error) {
+func (self *SQLStorage) GetKeysForPrefix(prefix string) ([]string, error) {
return nil, utils.ErrNotImplemented
}
+func (ms *SQLStorage) RebuildReverseForPrefix(prefix string) error {
+ return utils.ErrNotImplemented
+}
+
+func (self *SQLStorage) PreloadCacheForPrefix(prefix string) error {
+ return utils.ErrNotImplemented
+}
+
func (self *SQLStorage) CreateTablesFromScript(scriptPath string) error {
fileContent, err := ioutil.ReadFile(scriptPath)
if err != nil {
diff --git a/engine/storage_test.go b/engine/storage_test.go
index ff8da585d..0c7decd48 100644
--- a/engine/storage_test.go
+++ b/engine/storage_test.go
@@ -22,6 +22,7 @@ import (
"testing"
"time"
+ "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
)
@@ -102,7 +103,7 @@ func TestStorageCacheRefresh(t *testing.T) {
ratingStorage.GetDestination("T11")
ratingStorage.SetDestination(&Destination{"T11", []string{"1"}})
t.Log("Test cache refresh")
- err := ratingStorage.CacheRatingAll("TestStorageCacheRefresh")
+ err := ratingStorage.PreloadRatingCache()
if err != nil {
t.Error("Error cache rating: ", err)
}
@@ -144,8 +145,8 @@ func TestStorageGetAliases(t *testing.T) {
},
},
}
- accountingStorage.SetAlias(ala)
- accountingStorage.SetAlias(alb)
+ accountingStorage.SetAlias(ala, true)
+ accountingStorage.SetAlias(alb, true)
foundAlias, err := accountingStorage.GetAlias(ala.GetId(), true)
if err != nil || len(foundAlias.Values) != 1 {
t.Errorf("Alias get error %+v, %v: ", foundAlias, err)
@@ -181,7 +182,7 @@ func TestStorageCacheGetReverseAliases(t *testing.T) {
Subject: "b1",
Context: "*other",
}
- if x, ok := CacheGet(utils.REVERSE_ALIASES_PREFIX + "aaa" + "Subject" + utils.ALIAS_CONTEXT_RATING); ok {
+ if x, ok := cache2go.Get(utils.REVERSE_ALIASES_PREFIX + "aaa" + "Subject" + utils.ALIAS_CONTEXT_RATING); ok {
aliasKeys := x.(map[string]struct{})
_, found := aliasKeys[utils.ConcatenatedKey(ala.GetId(), utils.ANY)]
if !found {
@@ -190,7 +191,7 @@ func TestStorageCacheGetReverseAliases(t *testing.T) {
} else {
t.Error("Error getting reverse alias: ", err)
}
- if x, ok := CacheGet(utils.REVERSE_ALIASES_PREFIX + "aaa" + "Account" + "*other"); ok {
+ if x, ok := cache2go.Get(utils.REVERSE_ALIASES_PREFIX + "aaa" + "Account" + "*other"); ok {
aliasKeys := x.(map[string]struct{})
_, found := aliasKeys[utils.ConcatenatedKey(alb.GetId(), utils.ANY)]
if !found {
@@ -221,17 +222,17 @@ func TestStorageCacheRemoveCachedAliases(t *testing.T) {
accountingStorage.RemoveAlias(ala.GetId())
accountingStorage.RemoveAlias(alb.GetId())
- if _, ok := CacheGet(utils.ALIASES_PREFIX + ala.GetId()); ok {
+ if _, ok := cache2go.Get(utils.ALIASES_PREFIX + ala.GetId()); ok {
t.Error("Error removing cached alias: ", ok)
}
- if _, ok := CacheGet(utils.ALIASES_PREFIX + alb.GetId()); ok {
+ if _, ok := cache2go.Get(utils.ALIASES_PREFIX + alb.GetId()); ok {
t.Error("Error removing cached alias: ", ok)
}
- if _, ok := CacheGet(utils.REVERSE_ALIASES_PREFIX + "aaa" + utils.ALIAS_CONTEXT_RATING); ok {
+ if _, ok := cache2go.Get(utils.REVERSE_ALIASES_PREFIX + "aaa" + utils.ALIAS_CONTEXT_RATING); ok {
t.Error("Error removing cached reverse alias: ", ok)
}
- if _, ok := CacheGet(utils.REVERSE_ALIASES_PREFIX + "aaa" + utils.ALIAS_CONTEXT_RATING); ok {
+ if _, ok := cache2go.Get(utils.REVERSE_ALIASES_PREFIX + "aaa" + utils.ALIAS_CONTEXT_RATING); ok {
t.Error("Error removing cached reverse alias: ", ok)
}
}
diff --git a/engine/tp_reader.go b/engine/tp_reader.go
index 142e1dfd5..1191dbda5 100644
--- a/engine/tp_reader.go
+++ b/engine/tp_reader.go
@@ -252,7 +252,7 @@ func (tpr *TpReader) LoadRatingPlansFiltered(tag string) (bool, error) {
}
}
}
- if err := tpr.ratingStorage.SetRatingPlan(ratingPlan); err != nil {
+ if err := tpr.ratingStorage.SetRatingPlan(ratingPlan, true); err != nil {
return false, err
}
}
@@ -294,7 +294,7 @@ func (tpr *TpReader) LoadRatingPlans() (err error) {
return nil
}
-func (tpr *TpReader) LoadRatingProfilesFiltered(qriedRpf *TpRatingProfile) error {
+func (tpr *TpReader) LoadRatingProfilesFiltered(qriedRpf *TpRatingProfile, cache bool) error {
var resultRatingProfile *RatingProfile
mpTpRpfs, err := tpr.lr.GetTpRatingProfiles(qriedRpf)
if err != nil {
@@ -329,7 +329,7 @@ func (tpr *TpReader) LoadRatingProfilesFiltered(qriedRpf *TpRatingProfile) error
CdrStatQueueIds: strings.Split(tpRa.CdrStatQueueIds, utils.INFIELD_SEP),
})
}
- if err := tpr.ratingStorage.SetRatingProfile(resultRatingProfile); err != nil {
+ if err := tpr.ratingStorage.SetRatingProfile(resultRatingProfile, cache); err != nil {
return err
}
}
@@ -375,7 +375,7 @@ func (tpr *TpReader) LoadRatingProfiles() (err error) {
return nil
}
-func (tpr *TpReader) LoadSharedGroupsFiltered(tag string, save bool) (err error) {
+func (tpr *TpReader) LoadSharedGroupsFiltered(tag string, save, cache bool) (err error) {
tps, err := tpr.lr.GetTpSharedGroups(tpr.tpid, "")
if err != nil {
return err
@@ -402,7 +402,7 @@ func (tpr *TpReader) LoadSharedGroupsFiltered(tag string, save bool) (err error)
}
if save {
for _, sg := range tpr.sharedGroups {
- if err := tpr.ratingStorage.SetSharedGroup(sg); err != nil {
+ if err := tpr.ratingStorage.SetSharedGroup(sg, cache); err != nil {
return err
}
}
@@ -411,7 +411,7 @@ func (tpr *TpReader) LoadSharedGroupsFiltered(tag string, save bool) (err error)
}
func (tpr *TpReader) LoadSharedGroups() error {
- return tpr.LoadSharedGroupsFiltered(tpr.tpid, false)
+ return tpr.LoadSharedGroupsFiltered(tpr.tpid, false, false)
}
func (tpr *TpReader) LoadLCRs() (err error) {
@@ -431,7 +431,7 @@ func (tpr *TpReader) LoadLCRs() (err error) {
}
}
if !found && tpr.ratingStorage != nil {
- if keys, err := tpr.ratingStorage.GetKeysForPrefix(utils.RATING_PROFILE_PREFIX+ratingProfileSearchKey, true); err != nil {
+ if keys, err := tpr.ratingStorage.GetKeysForPrefix(utils.RATING_PROFILE_PREFIX + ratingProfileSearchKey); err != nil {
return fmt.Errorf("[LCR] error querying ratingDb %s", err.Error())
} else if len(keys) != 0 {
found = true
@@ -759,7 +759,7 @@ func (tpr *TpReader) LoadActionTriggers() (err error) {
return nil
}
-func (tpr *TpReader) LoadAccountActionsFiltered(qriedAA *TpAccountAction) error {
+func (tpr *TpReader) LoadAccountActionsFiltered(qriedAA *TpAccountAction, cache bool) error {
accountActions, err := tpr.lr.GetTpAccountActions(qriedAA)
if err != nil {
return errors.New(err.Error() + ": " + fmt.Sprintf("%+v", qriedAA))
@@ -856,7 +856,7 @@ func (tpr *TpReader) LoadAccountActionsFiltered(qriedAA *TpAccountAction) error
}
}
// write action plan
- err = tpr.ratingStorage.SetActionPlan(accountAction.ActionPlanId, actionPlan, false)
+ err = tpr.ratingStorage.SetActionPlan(accountAction.ActionPlanId, actionPlan, false, cache)
if err != nil {
return errors.New(err.Error() + " (SetActionPlan): " + accountAction.ActionPlanId)
}
@@ -961,7 +961,7 @@ func (tpr *TpReader) LoadAccountActionsFiltered(qriedAA *TpAccountAction) error
actionIDs = append(actionIDs, atr.ActionsID)
}
// write action triggers
- err = tpr.ratingStorage.SetActionTriggers(accountAction.ActionTriggersId, actionTriggers)
+ err = tpr.ratingStorage.SetActionTriggers(accountAction.ActionTriggersId, actionTriggers, cache)
if err != nil {
return errors.New(err.Error() + " (SetActionTriggers): " + accountAction.ActionTriggersId)
}
@@ -1076,7 +1076,7 @@ func (tpr *TpReader) LoadAccountActionsFiltered(qriedAA *TpAccountAction) error
}
// write actions
for k, as := range facts {
- err = tpr.ratingStorage.SetActions(k, as)
+ err = tpr.ratingStorage.SetActions(k, as, cache)
if err != nil {
return err
}
@@ -1141,7 +1141,7 @@ func (tpr *TpReader) LoadAccountActions() (err error) {
return nil
}
-func (tpr *TpReader) LoadDerivedChargersFiltered(filter *TpDerivedCharger, save bool) (err error) {
+func (tpr *TpReader) LoadDerivedChargersFiltered(filter *TpDerivedCharger, save, cache bool) (err error) {
tps, err := tpr.lr.GetTpDerivedChargers(filter)
if err != nil {
return err
@@ -1171,7 +1171,7 @@ func (tpr *TpReader) LoadDerivedChargersFiltered(filter *TpDerivedCharger, save
}
if save {
for dcsKey, dcs := range tpr.derivedChargers {
- if err := tpr.ratingStorage.SetDerivedChargers(dcsKey, dcs); err != nil {
+ if err := tpr.ratingStorage.SetDerivedChargers(dcsKey, dcs, cache); err != nil {
return err
}
}
@@ -1180,10 +1180,10 @@ func (tpr *TpReader) LoadDerivedChargersFiltered(filter *TpDerivedCharger, save
}
func (tpr *TpReader) LoadDerivedChargers() (err error) {
- return tpr.LoadDerivedChargersFiltered(&TpDerivedCharger{Tpid: tpr.tpid}, false)
+ return tpr.LoadDerivedChargersFiltered(&TpDerivedCharger{Tpid: tpr.tpid}, false, false)
}
-func (tpr *TpReader) LoadCdrStatsFiltered(tag string, save bool) (err error) {
+func (tpr *TpReader) LoadCdrStatsFiltered(tag string, save, cache bool) (err error) {
tps, err := tpr.lr.GetTpCdrStats(tpr.tpid, tag)
if err != nil {
return err
@@ -1306,7 +1306,7 @@ func (tpr *TpReader) LoadCdrStatsFiltered(tag string, save bool) (err error) {
return fmt.Errorf("could not get action triggers for cdr stats id %s: %s", cs.Id, triggerTag)
}
// write action triggers
- err = tpr.ratingStorage.SetActionTriggers(triggerTag, triggers)
+ err = tpr.ratingStorage.SetActionTriggers(triggerTag, triggers, cache)
if err != nil {
return errors.New(err.Error() + " (SetActionTriggers): " + triggerTag)
}
@@ -1410,7 +1410,7 @@ func (tpr *TpReader) LoadCdrStatsFiltered(tag string, save bool) (err error) {
if save {
// write actions
for k, as := range tpr.actions {
- err = tpr.ratingStorage.SetActions(k, as)
+ err = tpr.ratingStorage.SetActions(k, as, cache)
if err != nil {
return err
}
@@ -1425,7 +1425,7 @@ func (tpr *TpReader) LoadCdrStatsFiltered(tag string, save bool) (err error) {
}
func (tpr *TpReader) LoadCdrStats() error {
- return tpr.LoadCdrStatsFiltered("", false)
+ return tpr.LoadCdrStatsFiltered("", false, false)
}
func (tpr *TpReader) LoadUsersFiltered(filter *TpUser) (bool, error) {
@@ -1469,7 +1469,7 @@ func (tpr *TpReader) LoadUsers() error {
return err
}
-func (tpr *TpReader) LoadAliasesFiltered(filter *TpAlias) (bool, error) {
+func (tpr *TpReader) LoadAliasesFiltered(filter *TpAlias, cache bool) (bool, error) {
tpAliases, err := tpr.lr.GetTpAliases(filter)
alias := &Alias{
@@ -1497,7 +1497,7 @@ func (tpr *TpReader) LoadAliasesFiltered(filter *TpAlias) (bool, error) {
av.Pairs[tpAlias.Target][tpAlias.Original] = tpAlias.Alias
}
- tpr.accountingStorage.SetAlias(alias)
+ tpr.accountingStorage.SetAlias(alias, cache)
return len(tpAliases) > 0, err
}
@@ -1646,17 +1646,19 @@ func (tpr *TpReader) WriteToDatabase(flush, verbose bool) (err error) {
if err != nil {
return err
}
- // write reverse destination
-
if verbose {
log.Print("\t", d.Id, " : ", d.Prefixes)
}
}
+ err = tpr.ratingStorage.RebuildReverseForPrefix(utils.REVERSE_DESTINATION_PREFIX)
+ if err != nil {
+ return err
+ }
if verbose {
log.Print("Rating Plans:")
}
for _, rp := range tpr.ratingPlans {
- err = tpr.ratingStorage.SetRatingPlan(rp)
+ err = tpr.ratingStorage.SetRatingPlan(rp, false)
if err != nil {
return err
}
@@ -1668,7 +1670,7 @@ func (tpr *TpReader) WriteToDatabase(flush, verbose bool) (err error) {
log.Print("Rating Profiles:")
}
for _, rp := range tpr.ratingProfiles {
- err = tpr.ratingStorage.SetRatingProfile(rp)
+ err = tpr.ratingStorage.SetRatingProfile(rp, false)
if err != nil {
return err
}
@@ -1709,7 +1711,7 @@ func (tpr *TpReader) WriteToDatabase(flush, verbose bool) (err error) {
}
}
}
- err = tpr.ratingStorage.SetActionPlan(k, ap, false)
+ err = tpr.ratingStorage.SetActionPlan(k, ap, false, false)
if err != nil {
return err
}
@@ -1721,7 +1723,7 @@ func (tpr *TpReader) WriteToDatabase(flush, verbose bool) (err error) {
log.Print("Action Triggers:")
}
for k, atrs := range tpr.actionsTriggers {
- err = tpr.ratingStorage.SetActionTriggers(k, atrs)
+ err = tpr.ratingStorage.SetActionTriggers(k, atrs, false)
if err != nil {
return err
}
@@ -1733,7 +1735,7 @@ func (tpr *TpReader) WriteToDatabase(flush, verbose bool) (err error) {
log.Print("Shared Groups:")
}
for k, sg := range tpr.sharedGroups {
- err = tpr.ratingStorage.SetSharedGroup(sg)
+ err = tpr.ratingStorage.SetSharedGroup(sg, false)
if err != nil {
return err
}
@@ -1745,7 +1747,7 @@ func (tpr *TpReader) WriteToDatabase(flush, verbose bool) (err error) {
log.Print("LCR Rules:")
}
for k, lcr := range tpr.lcrs {
- err = tpr.ratingStorage.SetLCR(lcr)
+ err = tpr.ratingStorage.SetLCR(lcr, false)
if err != nil {
return err
}
@@ -1757,7 +1759,7 @@ func (tpr *TpReader) WriteToDatabase(flush, verbose bool) (err error) {
log.Print("Actions:")
}
for k, as := range tpr.actions {
- err = tpr.ratingStorage.SetActions(k, as)
+ err = tpr.ratingStorage.SetActions(k, as, false)
if err != nil {
return err
}
@@ -1781,7 +1783,7 @@ func (tpr *TpReader) WriteToDatabase(flush, verbose bool) (err error) {
log.Print("Derived Chargers:")
}
for key, dcs := range tpr.derivedChargers {
- err = tpr.ratingStorage.SetDerivedChargers(key, dcs)
+ err = tpr.ratingStorage.SetDerivedChargers(key, dcs, false)
if err != nil {
return err
}
@@ -1817,7 +1819,7 @@ func (tpr *TpReader) WriteToDatabase(flush, verbose bool) (err error) {
log.Print("Aliases:")
}
for _, al := range tpr.aliases {
- err = tpr.accountingStorage.SetAlias(al)
+ err = tpr.accountingStorage.SetAlias(al, false)
if err != nil {
return err
}
@@ -1825,6 +1827,10 @@ func (tpr *TpReader) WriteToDatabase(flush, verbose bool) (err error) {
log.Print("\t", al.GetId())
}
}
+ err = tpr.ratingStorage.RebuildReverseForPrefix(utils.REVERSE_ALIASES_PREFIX)
+ if err != nil {
+ return err
+ }
if verbose {
log.Print("ResourceLimits:")
}
@@ -1833,7 +1839,7 @@ func (tpr *TpReader) WriteToDatabase(flush, verbose bool) (err error) {
if err != nil {
return err
}
- if err = tpr.accountingStorage.SetResourceLimit(rl); err != nil {
+ if err = tpr.accountingStorage.SetResourceLimit(rl, false); err != nil {
return err
}
if verbose {
diff --git a/utils/consts.go b/utils/consts.go
index bae3ef681..bef1164c6 100644
--- a/utils/consts.go
+++ b/utils/consts.go
@@ -39,238 +39,240 @@ var (
)
const (
- VERSION = "0.9.1~rc8"
- DIAMETER_FIRMWARE_REVISION = 918
- REDIS_MAX_CONNS = 10
- POSTGRES = "postgres"
- MYSQL = "mysql"
- MONGO = "mongo"
- REDIS = "redis"
- LOCALHOST = "127.0.0.1"
- FSCDR_FILE_CSV = "freeswitch_file_csv"
- FSCDR_HTTP_JSON = "freeswitch_http_json"
- NOT_IMPLEMENTED = "not implemented"
- PREPAID = "prepaid"
- META_PREPAID = "*prepaid"
- POSTPAID = "postpaid"
- META_POSTPAID = "*postpaid"
- PSEUDOPREPAID = "pseudoprepaid"
- META_PSEUDOPREPAID = "*pseudoprepaid"
- META_RATED = "*rated"
- META_NONE = "*none"
- META_NOW = "*now"
- TBL_TP_TIMINGS = "tp_timings"
- TBL_TP_DESTINATIONS = "tp_destinations"
- TBL_TP_RATES = "tp_rates"
- TBL_TP_DESTINATION_RATES = "tp_destination_rates"
- TBL_TP_RATING_PLANS = "tp_rating_plans"
- TBL_TP_RATE_PROFILES = "tp_rating_profiles"
- TBL_TP_SHARED_GROUPS = "tp_shared_groups"
- TBL_TP_CDR_STATS = "tp_cdr_stats"
- TBL_TP_LCRS = "tp_lcr_rules"
- TBL_TP_ACTIONS = "tp_actions"
- TBL_TP_ACTION_PLANS = "tp_action_plans"
- TBL_TP_ACTION_TRIGGERS = "tp_action_triggers"
- TBL_TP_ACCOUNT_ACTIONS = "tp_account_actions"
- TBL_TP_DERIVED_CHARGERS = "tp_derived_chargers"
- TBL_TP_USERS = "tp_users"
- TBL_TP_ALIASES = "tp_aliases"
- TBLSMCosts = "sm_costs"
- TBLTPResourceLimits = "tp_resource_limits"
- TBL_CDRS = "cdrs"
- TIMINGS_CSV = "Timings.csv"
- DESTINATIONS_CSV = "Destinations.csv"
- RATES_CSV = "Rates.csv"
- DESTINATION_RATES_CSV = "DestinationRates.csv"
- RATING_PLANS_CSV = "RatingPlans.csv"
- RATING_PROFILES_CSV = "RatingProfiles.csv"
- SHARED_GROUPS_CSV = "SharedGroups.csv"
- LCRS_CSV = "LcrRules.csv"
- ACTIONS_CSV = "Actions.csv"
- ACTION_PLANS_CSV = "ActionPlans.csv"
- ACTION_TRIGGERS_CSV = "ActionTriggers.csv"
- ACCOUNT_ACTIONS_CSV = "AccountActions.csv"
- DERIVED_CHARGERS_CSV = "DerivedChargers.csv"
- CDR_STATS_CSV = "CdrStats.csv"
- USERS_CSV = "Users.csv"
- ALIASES_CSV = "Aliases.csv"
- ResourceLimitsCsv = "ResourceLimits.csv"
- ROUNDING_UP = "*up"
- ROUNDING_MIDDLE = "*middle"
- ROUNDING_DOWN = "*down"
- ANY = "*any"
- UNLIMITED = "*unlimited"
- ZERO = "*zero"
- ASAP = "*asap"
- USERS = "*users"
- COMMENT_CHAR = '#'
- CSV_SEP = ','
- FALLBACK_SEP = ';'
- INFIELD_SEP = ";"
- FIELDS_SEP = ","
- InInFieldSep = ":"
- STATIC_HDRVAL_SEP = "::"
- REGEXP_PREFIX = "~"
- FILTER_VAL_START = "("
- FILTER_VAL_END = ")"
- JSON = "json"
- GOB = "gob"
- MSGPACK = "msgpack"
- CSV_LOAD = "CSVLOAD"
- CGRID = "CGRID"
- TOR = "ToR"
- ORDERID = "OrderID"
- ACCID = "OriginID"
- InitialOriginID = "InitialOriginID"
- OriginIDPrefix = "OriginIDPrefix"
- CDRSOURCE = "Source"
- CDRHOST = "OriginHost"
- REQTYPE = "RequestType"
- DIRECTION = "Direction"
- TENANT = "Tenant"
- CATEGORY = "Category"
- ACCOUNT = "Account"
- SUBJECT = "Subject"
- DESTINATION = "Destination"
- SETUP_TIME = "SetupTime"
- ANSWER_TIME = "AnswerTime"
- USAGE = "Usage"
- LastUsed = "LastUsed"
- PDD = "PDD"
- SUPPLIER = "Supplier"
- MEDI_RUNID = "RunID"
- COST = "Cost"
- COST_DETAILS = "CostDetails"
- RATED = "rated"
- RATED_FLD = "Rated"
- PartialField = "Partial"
- DEFAULT_RUNID = "*default"
- META_DEFAULT = "*default"
- STATIC_VALUE_PREFIX = "^"
- CSV = "csv"
- FWV = "fwv"
- PartialCSV = "partial_csv"
- DRYRUN = "dry_run"
- META_COMBIMED = "*combimed"
- MetaInternal = "*internal"
- ZERO_RATING_SUBJECT_PREFIX = "*zero"
- OK = "OK"
- CDRE_FIXED_WIDTH = "fwv"
- XML_PROFILE_PREFIX = "*xml:"
- CDRE = "cdre"
- CDRC = "cdrc"
- MASK_CHAR = "*"
- CONCATENATED_KEY_SEP = ":"
- FORKED_CDR = "forked_cdr"
- UNIT_TEST = "UNIT_TEST"
- HDR_VAL_SEP = "/"
- MONETARY = "*monetary"
- SMS = "*sms"
- MMS = "*mms"
- GENERIC = "*generic"
- DATA = "*data"
- VOICE = "*voice"
- MAX_COST_FREE = "*free"
- MAX_COST_DISCONNECT = "*disconnect"
- HOURS = "hours"
- MINUTES = "minutes"
- NANOSECONDS = "nanoseconds"
- SECONDS = "seconds"
- OUT = "*out"
- IN = "*in"
- META_OUT = "*out"
- META_ANY = "*any"
- CDR_IMPORT = "cdr_import"
- CDR_EXPORT = "cdr_export"
- ASR = "ASR"
- ACD = "ACD"
- FILTER_REGEXP_TPL = "$1$2$3$4$5"
- TASKS_KEY = "tasks"
- ACTION_PLAN_PREFIX = "apl_"
- ACTION_TRIGGER_PREFIX = "atr_"
- RATING_PLAN_PREFIX = "rpl_"
- RATING_PROFILE_PREFIX = "rpf_"
- ACTION_PREFIX = "act_"
- SHARED_GROUP_PREFIX = "shg_"
- ACCOUNT_PREFIX = "acc_"
- DESTINATION_PREFIX = "dst_"
- LCR_PREFIX = "lcr_"
- DERIVEDCHARGERS_PREFIX = "dcs_"
- CDR_STATS_QUEUE_PREFIX = "csq_"
- PUBSUB_SUBSCRIBERS_PREFIX = "pss_"
- USERS_PREFIX = "usr_"
- ALIASES_PREFIX = "als_"
- ResourceLimitsPrefix = "rlm_"
- REVERSE_ALIASES_PREFIX = "rls_"
- CDR_STATS_PREFIX = "cst_"
- TEMP_DESTINATION_PREFIX = "tmp_"
- LOG_CALL_COST_PREFIX = "cco_"
- LOG_ACTION_TIMMING_PREFIX = "ltm_"
- LOG_ACTION_TRIGGER_PREFIX = "ltr_"
- VERSION_PREFIX = "ver_"
- LOG_ERR = "ler_"
- LOG_CDR = "cdr_"
- LOG_MEDIATED_CDR = "mcd_"
- LOADINST_KEY = "load_history"
- SESSION_MANAGER_SOURCE = "SMR"
- MEDIATOR_SOURCE = "MED"
- CDRS_SOURCE = "CDRS"
- SCHED_SOURCE = "SCH"
- RATER_SOURCE = "RAT"
- CREATE_CDRS_TABLES_SQL = "create_cdrs_tables.sql"
- CREATE_TARIFFPLAN_TABLES_SQL = "create_tariffplan_tables.sql"
- TEST_SQL = "TEST_SQL"
- DESTINATIONS_LOAD_THRESHOLD = 0.1
- META_CONSTANT = "*constant"
- META_FILLER = "*filler"
- META_HANDLER = "*handler"
- META_HTTP_POST = "*http_post"
- META_HTTP_JSON = "*http_json"
- META_HTTP_JSONRPC = "*http_jsonrpc"
- NANO_MULTIPLIER = 1000000000
- CGR_AUTHORIZE = "CGR_AUTHORIZE"
- CONFIG_DIR = "/etc/cgrates/"
- CGR_ACCOUNT = "cgr_account"
- CGR_SUPPLIER = "cgr_supplier"
- CGR_DESTINATION = "cgr_destination"
- CGR_SUBJECT = "cgr_subject"
- CGR_CATEGORY = "cgr_category"
- CGR_REQTYPE = "cgr_reqtype"
- CGR_TENANT = "cgr_tenant"
- CGR_TOR = "cgr_tor"
- CGR_ACCID = "cgr_accid"
- CGR_HOST = "cgr_host"
- CGR_PDD = "cgr_pdd"
- DISCONNECT_CAUSE = "DisconnectCause"
- CGR_DISCONNECT_CAUSE = "cgr_disconnectcause"
- CGR_COMPUTELCR = "cgr_computelcr"
- CGR_SUPPLIERS = "cgr_suppliers"
- CGRFlags = "cgr_flags"
- KAM_FLATSTORE = "kamailio_flatstore"
- OSIPS_FLATSTORE = "opensips_flatstore"
- MAX_DEBIT_CACHE_PREFIX = "MAX_DEBIT_"
- REFUND_INCR_CACHE_PREFIX = "REFUND_INCR_"
- REFUND_ROUND_CACHE_PREFIX = "REFUND_ROUND_"
- GET_SESS_RUNS_CACHE_PREFIX = "GET_SESS_RUNS_"
- GET_DERIV_MAX_SESS_TIME = "GET_DERIV_MAX_SESS_TIME_"
- LOG_CALL_COST_CACHE_PREFIX = "LOG_CALL_COSTS_"
- LCRCachePrefix = "LCR_"
- ALIAS_CONTEXT_RATING = "*rating"
- NOT_AVAILABLE = "N/A"
- CALL = "call"
- EXTRA_FIELDS = "ExtraFields"
- META_SURETAX = "*sure_tax"
- SURETAX = "suretax"
- DIAMETER_AGENT = "diameter_agent"
- COUNTER_EVENT = "*event"
- COUNTER_BALANCE = "*balance"
- EVENT_NAME = "EventName"
- COMPUTE_LCR = "ComputeLcr"
- CGR_AUTHORIZATION = "CgrAuthorization"
- CGR_SESSION_START = "CgrSessionStart"
- CGR_SESSION_UPDATE = "CgrSessionUpdate"
- CGR_SESSION_END = "CgrSessionEnd"
- CGR_LCR_REQUEST = "CgrLcrRequest"
+ VERSION = "0.9.1~rc8"
+ DIAMETER_FIRMWARE_REVISION = 918
+ REDIS_MAX_CONNS = 10
+ POSTGRES = "postgres"
+ MYSQL = "mysql"
+ MONGO = "mongo"
+ REDIS = "redis"
+ LOCALHOST = "127.0.0.1"
+ FSCDR_FILE_CSV = "freeswitch_file_csv"
+ FSCDR_HTTP_JSON = "freeswitch_http_json"
+ NOT_IMPLEMENTED = "not implemented"
+ PREPAID = "prepaid"
+ META_PREPAID = "*prepaid"
+ POSTPAID = "postpaid"
+ META_POSTPAID = "*postpaid"
+ PSEUDOPREPAID = "pseudoprepaid"
+ META_PSEUDOPREPAID = "*pseudoprepaid"
+ META_RATED = "*rated"
+ META_NONE = "*none"
+ META_NOW = "*now"
+ TBL_TP_TIMINGS = "tp_timings"
+ TBL_TP_DESTINATIONS = "tp_destinations"
+ TBL_TP_RATES = "tp_rates"
+ TBL_TP_DESTINATION_RATES = "tp_destination_rates"
+ TBL_TP_RATING_PLANS = "tp_rating_plans"
+ TBL_TP_RATE_PROFILES = "tp_rating_profiles"
+ TBL_TP_SHARED_GROUPS = "tp_shared_groups"
+ TBL_TP_CDR_STATS = "tp_cdr_stats"
+ TBL_TP_LCRS = "tp_lcr_rules"
+ TBL_TP_ACTIONS = "tp_actions"
+ TBL_TP_ACTION_PLANS = "tp_action_plans"
+ TBL_TP_ACTION_TRIGGERS = "tp_action_triggers"
+ TBL_TP_ACCOUNT_ACTIONS = "tp_account_actions"
+ TBL_TP_DERIVED_CHARGERS = "tp_derived_chargers"
+ TBL_TP_USERS = "tp_users"
+ TBL_TP_ALIASES = "tp_aliases"
+ TBLSMCosts = "sm_costs"
+ TBLTPResourceLimits = "tp_resource_limits"
+ TBL_CDRS = "cdrs"
+ TIMINGS_CSV = "Timings.csv"
+ DESTINATIONS_CSV = "Destinations.csv"
+ RATES_CSV = "Rates.csv"
+ DESTINATION_RATES_CSV = "DestinationRates.csv"
+ RATING_PLANS_CSV = "RatingPlans.csv"
+ RATING_PROFILES_CSV = "RatingProfiles.csv"
+ SHARED_GROUPS_CSV = "SharedGroups.csv"
+ LCRS_CSV = "LcrRules.csv"
+ ACTIONS_CSV = "Actions.csv"
+ ACTION_PLANS_CSV = "ActionPlans.csv"
+ ACTION_TRIGGERS_CSV = "ActionTriggers.csv"
+ ACCOUNT_ACTIONS_CSV = "AccountActions.csv"
+ DERIVED_CHARGERS_CSV = "DerivedChargers.csv"
+ CDR_STATS_CSV = "CdrStats.csv"
+ USERS_CSV = "Users.csv"
+ ALIASES_CSV = "Aliases.csv"
+ ResourceLimitsCsv = "ResourceLimits.csv"
+ ROUNDING_UP = "*up"
+ ROUNDING_MIDDLE = "*middle"
+ ROUNDING_DOWN = "*down"
+ ANY = "*any"
+ UNLIMITED = "*unlimited"
+ ZERO = "*zero"
+ ASAP = "*asap"
+ USERS = "*users"
+ COMMENT_CHAR = '#'
+ CSV_SEP = ','
+ FALLBACK_SEP = ';'
+ INFIELD_SEP = ";"
+ FIELDS_SEP = ","
+ InInFieldSep = ":"
+ STATIC_HDRVAL_SEP = "::"
+ REGEXP_PREFIX = "~"
+ FILTER_VAL_START = "("
+ FILTER_VAL_END = ")"
+ JSON = "json"
+ GOB = "gob"
+ MSGPACK = "msgpack"
+ CSV_LOAD = "CSVLOAD"
+ CGRID = "CGRID"
+ TOR = "ToR"
+ ORDERID = "OrderID"
+ ACCID = "OriginID"
+ InitialOriginID = "InitialOriginID"
+ OriginIDPrefix = "OriginIDPrefix"
+ CDRSOURCE = "Source"
+ CDRHOST = "OriginHost"
+ REQTYPE = "RequestType"
+ DIRECTION = "Direction"
+ TENANT = "Tenant"
+ CATEGORY = "Category"
+ ACCOUNT = "Account"
+ SUBJECT = "Subject"
+ DESTINATION = "Destination"
+ SETUP_TIME = "SetupTime"
+ ANSWER_TIME = "AnswerTime"
+ USAGE = "Usage"
+ LastUsed = "LastUsed"
+ PDD = "PDD"
+ SUPPLIER = "Supplier"
+ MEDI_RUNID = "RunID"
+ COST = "Cost"
+ COST_DETAILS = "CostDetails"
+ RATED = "rated"
+ RATED_FLD = "Rated"
+ PartialField = "Partial"
+ DEFAULT_RUNID = "*default"
+ META_DEFAULT = "*default"
+ STATIC_VALUE_PREFIX = "^"
+ CSV = "csv"
+ FWV = "fwv"
+ PartialCSV = "partial_csv"
+ DRYRUN = "dry_run"
+ META_COMBIMED = "*combimed"
+ MetaInternal = "*internal"
+ ZERO_RATING_SUBJECT_PREFIX = "*zero"
+ OK = "OK"
+ CDRE_FIXED_WIDTH = "fwv"
+ XML_PROFILE_PREFIX = "*xml:"
+ CDRE = "cdre"
+ CDRC = "cdrc"
+ MASK_CHAR = "*"
+ CONCATENATED_KEY_SEP = ":"
+ FORKED_CDR = "forked_cdr"
+ UNIT_TEST = "UNIT_TEST"
+ HDR_VAL_SEP = "/"
+ MONETARY = "*monetary"
+ SMS = "*sms"
+ MMS = "*mms"
+ GENERIC = "*generic"
+ DATA = "*data"
+ VOICE = "*voice"
+ MAX_COST_FREE = "*free"
+ MAX_COST_DISCONNECT = "*disconnect"
+ HOURS = "hours"
+ MINUTES = "minutes"
+ NANOSECONDS = "nanoseconds"
+ SECONDS = "seconds"
+ OUT = "*out"
+ IN = "*in"
+ META_OUT = "*out"
+ META_ANY = "*any"
+ CDR_IMPORT = "cdr_import"
+ CDR_EXPORT = "cdr_export"
+ ASR = "ASR"
+ ACD = "ACD"
+ FILTER_REGEXP_TPL = "$1$2$3$4$5"
+ TASKS_KEY = "tasks"
+ ACTION_PLAN_PREFIX = "apl_"
+ ACTION_TRIGGER_PREFIX = "atr_"
+ REVERSE_ACTION_TRIGGER_PREFIX = "rtr_"
+ RATING_PLAN_PREFIX = "rpl_"
+ RATING_PROFILE_PREFIX = "rpf_"
+ ACTION_PREFIX = "act_"
+ SHARED_GROUP_PREFIX = "shg_"
+ ACCOUNT_PREFIX = "acc_"
+ DESTINATION_PREFIX = "dst_"
+ REVERSE_DESTINATION_PREFIX = "rds_"
+ LCR_PREFIX = "lcr_"
+ DERIVEDCHARGERS_PREFIX = "dcs_"
+ CDR_STATS_QUEUE_PREFIX = "csq_"
+ PUBSUB_SUBSCRIBERS_PREFIX = "pss_"
+ USERS_PREFIX = "usr_"
+ ALIASES_PREFIX = "als_"
+ REVERSE_ALIASES_PREFIX = "rls_"
+ ResourceLimitsPrefix = "rlm_"
+ CDR_STATS_PREFIX = "cst_"
+ TEMP_DESTINATION_PREFIX = "tmp_"
+ LOG_CALL_COST_PREFIX = "cco_"
+ LOG_ACTION_TIMMING_PREFIX = "ltm_"
+ LOG_ACTION_TRIGGER_PREFIX = "ltr_"
+ VERSION_PREFIX = "ver_"
+ LOG_ERR = "ler_"
+ LOG_CDR = "cdr_"
+ LOG_MEDIATED_CDR = "mcd_"
+ LOADINST_KEY = "load_history"
+ SESSION_MANAGER_SOURCE = "SMR"
+ MEDIATOR_SOURCE = "MED"
+ CDRS_SOURCE = "CDRS"
+ SCHED_SOURCE = "SCH"
+ RATER_SOURCE = "RAT"
+ CREATE_CDRS_TABLES_SQL = "create_cdrs_tables.sql"
+ CREATE_TARIFFPLAN_TABLES_SQL = "create_tariffplan_tables.sql"
+ TEST_SQL = "TEST_SQL"
+ DESTINATIONS_LOAD_THRESHOLD = 0.1
+ META_CONSTANT = "*constant"
+ META_FILLER = "*filler"
+ META_HANDLER = "*handler"
+ META_HTTP_POST = "*http_post"
+ META_HTTP_JSON = "*http_json"
+ META_HTTP_JSONRPC = "*http_jsonrpc"
+ NANO_MULTIPLIER = 1000000000
+ CGR_AUTHORIZE = "CGR_AUTHORIZE"
+ CONFIG_DIR = "/etc/cgrates/"
+ CGR_ACCOUNT = "cgr_account"
+ CGR_SUPPLIER = "cgr_supplier"
+ CGR_DESTINATION = "cgr_destination"
+ CGR_SUBJECT = "cgr_subject"
+ CGR_CATEGORY = "cgr_category"
+ CGR_REQTYPE = "cgr_reqtype"
+ CGR_TENANT = "cgr_tenant"
+ CGR_TOR = "cgr_tor"
+ CGR_ACCID = "cgr_accid"
+ CGR_HOST = "cgr_host"
+ CGR_PDD = "cgr_pdd"
+ DISCONNECT_CAUSE = "DisconnectCause"
+ CGR_DISCONNECT_CAUSE = "cgr_disconnectcause"
+ CGR_COMPUTELCR = "cgr_computelcr"
+ CGR_SUPPLIERS = "cgr_suppliers"
+ CGRFlags = "cgr_flags"
+ KAM_FLATSTORE = "kamailio_flatstore"
+ OSIPS_FLATSTORE = "opensips_flatstore"
+ MAX_DEBIT_CACHE_PREFIX = "MAX_DEBIT_"
+ REFUND_INCR_CACHE_PREFIX = "REFUND_INCR_"
+ REFUND_ROUND_CACHE_PREFIX = "REFUND_ROUND_"
+ GET_SESS_RUNS_CACHE_PREFIX = "GET_SESS_RUNS_"
+ GET_DERIV_MAX_SESS_TIME = "GET_DERIV_MAX_SESS_TIME_"
+ LOG_CALL_COST_CACHE_PREFIX = "LOG_CALL_COSTS_"
+ LCRCachePrefix = "LCR_"
+ ALIAS_CONTEXT_RATING = "*rating"
+ NOT_AVAILABLE = "N/A"
+ CALL = "call"
+ EXTRA_FIELDS = "ExtraFields"
+ META_SURETAX = "*sure_tax"
+ SURETAX = "suretax"
+ DIAMETER_AGENT = "diameter_agent"
+ COUNTER_EVENT = "*event"
+ COUNTER_BALANCE = "*balance"
+ EVENT_NAME = "EventName"
+ COMPUTE_LCR = "ComputeLcr"
+ CGR_AUTHORIZATION = "CgrAuthorization"
+ CGR_SESSION_START = "CgrSessionStart"
+ CGR_SESSION_UPDATE = "CgrSessionUpdate"
+ CGR_SESSION_END = "CgrSessionEnd"
+ CGR_LCR_REQUEST = "CgrLcrRequest"
// action trigger threshold types
TRIGGER_MIN_EVENT_COUNTER = "*min_event_counter"
TRIGGER_MIN_BALANCE_COUNTER = "*min_balance_counter"