diff --git a/apier/v1/apier.go b/apier/v1/apier.go
index b9932fd3e..cd3c1b4fb 100644
--- a/apier/v1/apier.go
+++ b/apier/v1/apier.go
@@ -28,7 +28,6 @@ import (
"strings"
"time"
- "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/scheduler"
@@ -813,15 +812,15 @@ func (self *ApierV1) ReloadCache(attrs utils.AttrReloadCache, reply *string) err
func (self *ApierV1) GetCacheStats(attrs utils.AttrCacheStats, reply *utils.CacheStats) error {
cs := new(utils.CacheStats)
- cs.Destinations = cache2go.CountEntries(utils.DESTINATION_PREFIX)
- cs.RatingPlans = cache2go.CountEntries(utils.RATING_PLAN_PREFIX)
- cs.RatingProfiles = cache2go.CountEntries(utils.RATING_PROFILE_PREFIX)
- cs.Actions = cache2go.CountEntries(utils.ACTION_PREFIX)
- cs.ActionPlans = cache2go.CountEntries(utils.ACTION_PLAN_PREFIX)
- cs.SharedGroups = cache2go.CountEntries(utils.SHARED_GROUP_PREFIX)
- cs.DerivedChargers = cache2go.CountEntries(utils.DERIVEDCHARGERS_PREFIX)
- cs.LcrProfiles = cache2go.CountEntries(utils.LCR_PREFIX)
- cs.Aliases = cache2go.CountEntries(utils.ALIASES_PREFIX)
+ cs.Destinations = engine.CacheCountEntries(utils.DESTINATION_PREFIX)
+ cs.RatingPlans = engine.CacheCountEntries(utils.RATING_PLAN_PREFIX)
+ cs.RatingProfiles = engine.CacheCountEntries(utils.RATING_PROFILE_PREFIX)
+ cs.Actions = engine.CacheCountEntries(utils.ACTION_PREFIX)
+ cs.ActionPlans = engine.CacheCountEntries(utils.ACTION_PLAN_PREFIX)
+ cs.SharedGroups = engine.CacheCountEntries(utils.SHARED_GROUP_PREFIX)
+ cs.DerivedChargers = engine.CacheCountEntries(utils.DERIVEDCHARGERS_PREFIX)
+ cs.LcrProfiles = engine.CacheCountEntries(utils.LCR_PREFIX)
+ cs.Aliases = engine.CacheCountEntries(utils.ALIASES_PREFIX)
if self.CdrStatsSrv != nil {
var queueIds []string
if err := self.CdrStatsSrv.Call("CDRStatsV1.GetQueueIds", 0, &queueIds); err != nil {
diff --git a/apier/v1/triggers.go b/apier/v1/triggers.go
index eff24c748..1de722dd9 100644
--- a/apier/v1/triggers.go
+++ b/apier/v1/triggers.go
@@ -1,6 +1,8 @@
package v1
import (
+ "log"
+
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
@@ -217,6 +219,7 @@ func (self *ApierV1) SetAccountActionTriggers(attr AttrSetAccountActionTriggers,
} else {
return 0, err
}
+ log.Print("HERE: ", account.ActionTriggers)
for _, at := range account.ActionTriggers {
if (attr.UniqueID == "" || at.UniqueID == attr.UniqueID) &&
(attr.GroupID == "" || at.ID == attr.GroupID) {
diff --git a/cache2go/.gitignore b/cache2go/.gitignore
deleted file mode 100644
index 00268614f..000000000
--- a/cache2go/.gitignore
+++ /dev/null
@@ -1,22 +0,0 @@
-# Compiled Object files, Static and Dynamic libs (Shared Objects)
-*.o
-*.a
-*.so
-
-# Folders
-_obj
-_test
-
-# Architecture specific extensions/prefixes
-*.[568vq]
-[568vq].out
-
-*.cgo1.go
-*.cgo2.c
-_cgo_defun.c
-_cgo_gotypes.go
-_cgo_export.*
-
-_testmain.go
-
-*.exe
diff --git a/cache2go/.travis.yml b/cache2go/.travis.yml
deleted file mode 100644
index ffc3d37e0..000000000
--- a/cache2go/.travis.yml
+++ /dev/null
@@ -1,6 +0,0 @@
-language: go
-
-notifications:
- email:
- on_success: change
- on_failure: always
diff --git a/cache2go/LICENSE.txt b/cache2go/LICENSE.txt
deleted file mode 100644
index 9bdbcbf59..000000000
--- a/cache2go/LICENSE.txt
+++ /dev/null
@@ -1,9 +0,0 @@
-Copyright (c) 2012, Radu Ioan Fericean
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
-
-Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
-Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
-Neither the name of Radu Ioan Fericean nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/cache2go/README.md b/cache2go/README.md
deleted file mode 100644
index ca572d755..000000000
--- a/cache2go/README.md
+++ /dev/null
@@ -1,10 +0,0 @@
-cache2go
-=====
-
-Golang simple object caching library with expiration capabilities.
-
-See the test file for wroking examples.
-
-API docs [here](http://go.pkgdoc.org/github.com/rif/cache2go).
-
-Continous integration: [](http://travis-ci.org/rif/cache2go)
diff --git a/cache2go/cache_test.go b/cache2go/cache_test.go
deleted file mode 100644
index ce9f50e92..000000000
--- a/cache2go/cache_test.go
+++ /dev/null
@@ -1,120 +0,0 @@
-package cache2go
-
-import "testing"
-
-func TestRemKey(t *testing.T) {
- Cache("t11_mm", "test")
- if t1, err := Get("t11_mm"); err != nil || t1 != "test" {
- t.Error("Error setting cache: ", err, t1)
- }
- RemKey("t11_mm")
- if t1, err := Get("t11_mm"); err == nil || t1 == "test" {
- t.Error("Error removing cached key")
- }
-}
-
-func TestTransaction(t *testing.T) {
- BeginTransaction()
- Cache("t11_mm", "test")
- if t1, err := Get("t11_mm"); err == nil || t1 == "test" {
- t.Error("Error in transaction cache")
- }
- Cache("t12_mm", "test")
- RemKey("t11_mm")
- CommitTransaction()
- if t1, err := Get("t12_mm"); err != nil || t1 != "test" {
- t.Error("Error commiting transaction")
- }
- if t1, err := Get("t11_mm"); err == nil || t1 == "test" {
- t.Error("Error in transaction cache")
- }
-}
-
-func TestTransactionRem(t *testing.T) {
- BeginTransaction()
- Cache("t21_mm", "test")
- Cache("t21_nn", "test")
- RemPrefixKey("t21_")
- CommitTransaction()
- if t1, err := Get("t21_mm"); err == nil || t1 == "test" {
- t.Error("Error commiting transaction")
- }
- if t1, err := Get("t21_nn"); err == nil || t1 == "test" {
- t.Error("Error in transaction cache")
- }
-}
-
-func TestTransactionRollback(t *testing.T) {
- BeginTransaction()
- Cache("t31_mm", "test")
- if t1, err := Get("t31_mm"); err == nil || t1 == "test" {
- t.Error("Error in transaction cache")
- }
- Cache("t32_mm", "test")
- RollbackTransaction()
- if t1, err := Get("t32_mm"); err == nil || t1 == "test" {
- t.Error("Error commiting transaction")
- }
- if t1, err := Get("t31_mm"); err == nil || t1 == "test" {
- t.Error("Error in transaction cache")
- }
-}
-
-func TestTransactionRemBefore(t *testing.T) {
- BeginTransaction()
- RemPrefixKey("t41_")
- Cache("t41_mm", "test")
- Cache("t41_nn", "test")
- CommitTransaction()
- if t1, err := Get("t41_mm"); err != nil || t1 != "test" {
- t.Error("Error commiting transaction")
- }
- if t1, err := Get("t41_nn"); err != nil || t1 != "test" {
- t.Error("Error in transaction cache")
- }
-}
-
-func TestRemPrefixKey(t *testing.T) {
- Cache("xxx_t1", "test")
- Cache("yyy_t1", "test")
- RemPrefixKey("xxx_")
- _, errX := Get("xxx_t1")
- _, errY := Get("yyy_t1")
- if errX == nil || errY != nil {
- t.Error("Error removing prefix: ", errX, errY)
- }
-}
-
-func TestCachePush(t *testing.T) {
- Push("ccc_t1", "1")
- Push("ccc_t1", "2")
- v, err := Get("ccc_t1")
- if err != nil || len(v.(map[interface{}]struct{})) != 2 {
- t.Error("Error in cache push: ", v)
- }
-}
-
-func TestCachePop(t *testing.T) {
- Push("ccc_t1", "1")
- Push("ccc_t1", "2")
- v, err := Get("ccc_t1")
- if err != nil || len(v.(map[interface{}]struct{})) != 2 {
- t.Error("Error in cache push: ", v)
- }
- Pop("ccc_t1", "1")
- v, err = Get("ccc_t1")
- if err != nil || len(v.(map[interface{}]struct{})) != 1 {
- t.Error("Error in cache pop: ", v)
- }
-}
-
-func TestCount(t *testing.T) {
- Cache("dst_A1", "1")
- Cache("dst_A2", "2")
- Cache("rpf_A3", "3")
- Cache("dst_A4", "4")
- Cache("dst_A5", "5")
- if CountEntries("dst_") != 4 {
- t.Error("Error countiong entries: ", CountEntries("dst_"))
- }
-}
diff --git a/cmd/cgr-engine/cgr-engine.go b/cmd/cgr-engine/cgr-engine.go
index 07253dba0..1372cb828 100644
--- a/cmd/cgr-engine/cgr-engine.go
+++ b/cmd/cgr-engine/cgr-engine.go
@@ -34,7 +34,6 @@ import (
"github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/apier/v2"
"github.com/cgrates/cgrates/balancer2go"
- "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/cdrc"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
@@ -419,12 +418,12 @@ func startAliasesServer(internalAliaseSChan chan rpcclient.RpcClientConnection,
return
}
- if err := cache2go.Save("/tmp/cgr_cache", []string{utils.ALIASES_PREFIX}); err != nil {
+ if err := engine.CacheSave("/tmp/cgr_cache", []string{utils.ALIASES_PREFIX}); err != nil {
utils.Logger.Emerg(fmt.Sprintf("could not save cache file: " + err.Error()))
}
utils.Logger.Info(fmt.Sprintf("Cache accounting save time: %v", time.Since(start)))
} else {
- if err := cache2go.Load("/tmp/cgr_cache", []string{utils.ALIASES_PREFIX}); err != nil {
+ if err := engine.CacheLoad("/tmp/cgr_cache", []string{utils.ALIASES_PREFIX}); err != nil {
utils.Logger.Crit("could not load cache file: " + err.Error())
exitChan <- true
return
diff --git a/cmd/cgr-engine/rater.go b/cmd/cgr-engine/rater.go
index f121b3fc9..1271b169f 100644
--- a/cmd/cgr-engine/rater.go
+++ b/cmd/cgr-engine/rater.go
@@ -19,14 +19,12 @@ along with this program. If not, see
package main
import (
- "encoding/gob"
"fmt"
"time"
"github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/apier/v2"
"github.com/cgrates/cgrates/balancer2go"
- "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/history"
"github.com/cgrates/cgrates/scheduler"
@@ -34,16 +32,16 @@ import (
"github.com/cgrates/rpcclient"
)
-func init() {
+/*func init() {
gob.Register(map[interface{}]struct{}{})
gob.Register(engine.Actions{})
gob.RegisterName("github.com/cgrates/cgrates/engine.ActionPlan", &engine.ActionPlan{})
gob.Register([]*utils.LoadInstance{})
- gob.RegisterName("github.com/cgrates/cgrates/engine.RatingPlan", engine.RatingPlan{})
- gob.RegisterName("github.com/cgrates/cgrates/engine.RatingProfile", engine.RatingProfile{})
- gob.RegisterName("github.com/cgrates/cgrates/utils.DerivedChargers", utils.DerivedChargers{})
+ gob.RegisterName("github.com/cgrates/cgrates/engine.RatingPlan", &engine.RatingPlan{})
+ gob.RegisterName("github.com/cgrates/cgrates/engine.RatingProfile", &engine.RatingProfile{})
+ gob.RegisterName("github.com/cgrates/cgrates/utils.DerivedChargers", &utils.DerivedChargers{})
gob.Register(engine.AliasValues{})
-}
+}*/
func startBalancer(internalBalancerChan chan *balancer2go.Balancer, stopHandled *bool, exitChan chan bool) {
bal := balancer2go.NewBalancer()
@@ -96,12 +94,12 @@ func startRater(internalRaterChan chan rpcclient.RpcClientConnection, cacheDoneC
return
}
- if err := cache2go.Save("/tmp/cgr_cache", []string{utils.DESTINATION_PREFIX, utils.RATING_PLAN_PREFIX, utils.RATING_PROFILE_PREFIX, utils.LCR_PREFIX, utils.DERIVEDCHARGERS_PREFIX, utils.ACTION_PREFIX, utils.ACTION_PLAN_PREFIX, utils.SHARED_GROUP_PREFIX}); err != nil {
+ if err := engine.CacheSave("/tmp/cgr_cache", []string{utils.DESTINATION_PREFIX, utils.RATING_PLAN_PREFIX, utils.RATING_PROFILE_PREFIX, utils.LCR_PREFIX, utils.DERIVEDCHARGERS_PREFIX, utils.ACTION_PREFIX, utils.ACTION_PLAN_PREFIX, utils.SHARED_GROUP_PREFIX}); err != nil {
utils.Logger.Emerg(fmt.Sprintf("could not save cache file: " + err.Error()))
}
utils.Logger.Info(fmt.Sprintf("Cache rating save time: %v", time.Since(start)))
} else {
- if err := cache2go.Load("/tmp/cgr_cache", []string{utils.DESTINATION_PREFIX, utils.RATING_PLAN_PREFIX, utils.RATING_PROFILE_PREFIX, utils.LCR_PREFIX, utils.DERIVEDCHARGERS_PREFIX, utils.ACTION_PREFIX, utils.ACTION_PLAN_PREFIX, utils.SHARED_GROUP_PREFIX}); err != nil {
+ if err := engine.CacheLoad("/tmp/cgr_cache", []string{utils.DESTINATION_PREFIX, utils.RATING_PLAN_PREFIX, utils.RATING_PROFILE_PREFIX, utils.LCR_PREFIX, utils.DERIVEDCHARGERS_PREFIX, utils.ACTION_PREFIX, utils.ACTION_PLAN_PREFIX, utils.SHARED_GROUP_PREFIX}); err != nil {
utils.Logger.Crit("could not load cache file: " + err.Error())
exitChan <- true
return
diff --git a/engine/account.go b/engine/account.go
index 69598ed6e..dd7fe6093 100644
--- a/engine/account.go
+++ b/engine/account.go
@@ -24,7 +24,6 @@ import (
"fmt"
"time"
- "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/structmatcher"
"github.com/cgrates/cgrates/utils"
@@ -305,12 +304,12 @@ 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, err := cache2go.Get(utils.DESTINATION_PREFIX + p); err == nil {
- destIds := x.(map[interface{}]struct{})
+ if x, err := CacheGet(utils.DESTINATION_PREFIX + p); err == nil {
+ destIds := x.(map[string]struct{})
foundResult := false
allInclude := true // wheter it is excluded or included
for dId, _ := range destIds {
- inclDest, found := b.DestinationIDs[dId.(string)]
+ inclDest, found := b.DestinationIDs[dId]
if found {
foundResult = true
allInclude = allInclude && inclDest
diff --git a/engine/account_test.go b/engine/account_test.go
index 6cedc5995..6a1192c12 100644
--- a/engine/account_test.go
+++ b/engine/account_test.go
@@ -22,7 +22,6 @@ import (
"testing"
"time"
- "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
)
@@ -1165,7 +1164,7 @@ func TestDebitShared(t *testing.T) {
accountingStorage.SetAccount(groupie)
ratingStorage.SetSharedGroup(sg)
- cache2go.Cache(utils.SHARED_GROUP_PREFIX+"SG_TEST", sg)
+ CacheSet(utils.SHARED_GROUP_PREFIX+"SG_TEST", sg)
cc, err := rif.debitCreditBalance(cd, false, false, true)
if err != nil {
t.Error("Error debiting balance: ", err)
@@ -1235,7 +1234,7 @@ func TestMaxDurationShared(t *testing.T) {
accountingStorage.SetAccount(groupie)
ratingStorage.SetSharedGroup(sg)
- cache2go.Cache(utils.SHARED_GROUP_PREFIX+"SG_TEST", sg)
+ CacheSet(utils.SHARED_GROUP_PREFIX+"SG_TEST", sg)
duration, err := cd.getMaxSessionDuration(rif)
if err != nil {
t.Error("Error getting max session duration from shared group: ", err)
diff --git a/engine/actions_test.go b/engine/actions_test.go
index 958d19989..63a2e78da 100644
--- a/engine/actions_test.go
+++ b/engine/actions_test.go
@@ -26,7 +26,6 @@ import (
"testing"
"time"
- "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
)
@@ -1283,12 +1282,12 @@ func TestActionSetDDestination(t *testing.T) {
if d, err := ratingStorage.GetDestination("*ddc_test"); err != nil || !reflect.DeepEqual(d, origD) {
t.Error("Error storing destination: ", d, err)
}
- x1, err := cache2go.Get(utils.DESTINATION_PREFIX + "111")
- if _, ok := x1.(map[interface{}]struct{})["*ddc_test"]; err != nil || !ok {
+ x1, err := CacheGet(utils.DESTINATION_PREFIX + "111")
+ if _, ok := x1.(map[string]struct{})["*ddc_test"]; err != nil || !ok {
t.Error("Error cacheing destination: ", x1)
}
- x1, err = cache2go.Get(utils.DESTINATION_PREFIX + "222")
- if _, ok := x1.(map[interface{}]struct{})["*ddc_test"]; err != nil || !ok {
+ x1, err = CacheGet(utils.DESTINATION_PREFIX + "222")
+ if _, ok := x1.(map[string]struct{})["*ddc_test"]; err != nil || !ok {
t.Error("Error cacheing destination: ", x1)
}
setddestinations(acc, &StatsQueueTriggered{Metrics: map[string]float64{"333": 1, "444": 1}}, nil, nil)
@@ -1299,20 +1298,20 @@ func TestActionSetDDestination(t *testing.T) {
!utils.IsSliceMember(d.Prefixes, "444") {
t.Error("Error storing destination: ", d, err)
}
- x1, err = cache2go.Get(utils.DESTINATION_PREFIX + "111")
+ x1, err = CacheGet(utils.DESTINATION_PREFIX + "111")
if err == nil {
t.Error("Error cacheing destination: ", x1)
}
- x1, err = cache2go.Get(utils.DESTINATION_PREFIX + "222")
+ x1, err = CacheGet(utils.DESTINATION_PREFIX + "222")
if err == nil {
t.Error("Error cacheing destination: ", x1)
}
- x1, err = cache2go.Get(utils.DESTINATION_PREFIX + "333")
- if _, ok := x1.(map[interface{}]struct{})["*ddc_test"]; err != nil || !ok {
+ x1, err = CacheGet(utils.DESTINATION_PREFIX + "333")
+ if _, ok := x1.(map[string]struct{})["*ddc_test"]; err != nil || !ok {
t.Error("Error cacheing destination: ", x1)
}
- x1, err = cache2go.Get(utils.DESTINATION_PREFIX + "444")
- if _, ok := x1.(map[interface{}]struct{})["*ddc_test"]; err != nil || !ok {
+ x1, err = CacheGet(utils.DESTINATION_PREFIX + "444")
+ if _, ok := x1.(map[string]struct{})["*ddc_test"]; err != nil || !ok {
t.Error("Error cacheing destination: ", x1)
}
}
diff --git a/engine/aliases.go b/engine/aliases.go
index a927cc9b8..107e23068 100644
--- a/engine/aliases.go
+++ b/engine/aliases.go
@@ -6,7 +6,6 @@ import (
"strings"
"sync"
- "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
"github.com/cgrates/rpcclient"
)
@@ -120,7 +119,7 @@ func (al *Alias) SetReverseCache() {
for target, pairs := range value.Pairs {
for _, alias := range pairs {
rKey := strings.Join([]string{utils.REVERSE_ALIASES_PREFIX, alias, target, al.Context}, "")
- cache2go.Push(rKey, utils.ConcatenatedKey(al.GetId(), value.DestinationId))
+ CachePush(rKey, utils.ConcatenatedKey(al.GetId(), value.DestinationId))
}
}
}
@@ -132,7 +131,7 @@ func (al *Alias) RemoveReverseCache() {
for target, pairs := range value.Pairs {
for _, alias := range pairs {
rKey := utils.REVERSE_ALIASES_PREFIX + alias + target + al.Context
- cache2go.Pop(rKey, tmpKey)
+ CachePop(rKey, tmpKey)
}
}
}
@@ -252,7 +251,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, err := cache2go.Get(rKey); err == nil {
+ if x, err := CacheGet(rKey); err == nil {
existingKeys := x.(map[interface{}]struct{})
for iKey := range existingKeys {
key := iKey.(string)
@@ -289,7 +288,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, err := cache2go.Get(rKey); err == nil {
+ if x, err := CacheGet(rKey); err == nil {
existingKeys := x.(map[interface{}]struct{})
for iKey := range existingKeys {
key := iKey.(string)
@@ -341,11 +340,10 @@ func (am *AliasHandler) GetMatchingAlias(attr *AttrMatchingAlias, result *string
}
// check destination ids
for _, p := range utils.SplitPrefix(attr.Destination, MIN_PREFIX_MATCH) {
- if x, err := cache2go.Get(utils.DESTINATION_PREFIX + p); err == nil {
- destIds := x.(map[interface{}]struct{})
+ if x, err := CacheGet(utils.DESTINATION_PREFIX + p); err == nil {
+ destIds := x.(map[string]struct{})
for _, value := range values {
- for idId := range destIds {
- dId := idId.(string)
+ for dId := range destIds {
if value.DestinationId == utils.ANY || value.DestinationId == dId {
if origAliasMap, ok := value.Pairs[attr.Target]; ok {
if alias, ok := origAliasMap[attr.Original]; ok || attr.Original == "" || attr.Original == utils.ANY {
@@ -422,11 +420,10 @@ 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, err := cache2go.Get(utils.DESTINATION_PREFIX + p); err == nil {
- destIds := x.(map[interface{}]struct{})
+ if x, err := CacheGet(utils.DESTINATION_PREFIX + p); err == nil {
+ destIds := x.(map[string]struct{})
for _, value := range values {
- for idId := range destIds {
- dId := idId.(string)
+ for dId := range destIds {
if value.DestinationId == utils.ANY || value.DestinationId == dId {
rightPairs = value.Pairs
}
diff --git a/engine/aliases_test.go b/engine/aliases_test.go
index 43708d128..f42d184c3 100644
--- a/engine/aliases_test.go
+++ b/engine/aliases_test.go
@@ -3,7 +3,6 @@ package engine
import (
"testing"
- "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
)
@@ -208,32 +207,32 @@ func TestAliasesLoadAlias(t *testing.T) {
func TestAliasesCache(t *testing.T) {
key := "*out:cgrates.org:call:remo:remo:*rating"
- a, err := cache2go.Get(utils.ALIASES_PREFIX + key)
+ a, err := CacheGet(utils.ALIASES_PREFIX + key)
if err != nil || a == nil {
- //log.Printf("Test: %+v", cache2go.GetEntriesKeys(utils.REVERSE_ALIASES_PREFIX))
+ //log.Printf("Test: %+v", CacheGetEntriesKeys(utils.REVERSE_ALIASES_PREFIX))
t.Error("Error getting alias from cache: ", err, a)
}
rKey1 := "minuAccount*rating"
- ra1, err := cache2go.Get(utils.REVERSE_ALIASES_PREFIX + rKey1)
- if err != nil || len(ra1.(map[interface{}]struct{})) != 2 {
+ ra1, err := CacheGet(utils.REVERSE_ALIASES_PREFIX + rKey1)
+ if err != nil || len(ra1.(map[string]struct{})) != 2 {
t.Error("Error getting reverse alias 1: ", ra1)
}
rKey2 := "minuSubject*rating"
- ra2, err := cache2go.Get(utils.REVERSE_ALIASES_PREFIX + rKey2)
- if err != nil || len(ra2.(map[interface{}]struct{})) != 2 {
+ ra2, err := CacheGet(utils.REVERSE_ALIASES_PREFIX + rKey2)
+ if err != nil || len(ra2.(map[string]struct{})) != 2 {
t.Error("Error getting reverse alias 2: ", ra2)
}
accountingStorage.RemoveAlias(key)
- a, err = cache2go.Get(utils.ALIASES_PREFIX + key)
+ a, err = CacheGet(utils.ALIASES_PREFIX + key)
if err == nil {
t.Error("Error getting alias from cache: ", err)
}
- ra1, err = cache2go.Get(utils.REVERSE_ALIASES_PREFIX + rKey1)
- if err != nil || len(ra1.(map[interface{}]struct{})) != 1 {
+ ra1, err = CacheGet(utils.REVERSE_ALIASES_PREFIX + rKey1)
+ if err != nil || len(ra1.(map[string]struct{})) != 1 {
t.Error("Error getting reverse alias 1: ", ra1)
}
- ra2, err = cache2go.Get(utils.REVERSE_ALIASES_PREFIX + rKey2)
- if err != nil || len(ra2.(map[interface{}]struct{})) != 1 {
+ ra2, err = CacheGet(utils.REVERSE_ALIASES_PREFIX + rKey2)
+ if err != nil || 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 ce7704f96..4cdc1162d 100644
--- a/engine/balances.go
+++ b/engine/balances.go
@@ -26,7 +26,6 @@ import (
"strings"
"time"
- "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
)
@@ -196,11 +195,11 @@ 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, err := cache2go.Get(utils.DESTINATION_PREFIX + p); err == nil {
- destIDs := x.(map[interface{}]struct{})
+ if x, err := CacheGet(utils.DESTINATION_PREFIX + p); err == nil {
+ destIDs := x.(map[string]struct{})
for dID := range destIDs {
- if b.DestinationIDs[dID.(string)] == true {
- return p, dID.(string)
+ if b.DestinationIDs[dID] == true {
+ return p, dID
}
}
}
diff --git a/cache2go/cache.go b/engine/cache.go
similarity index 75%
rename from cache2go/cache.go
rename to engine/cache.go
index 0a2500ff8..716190bc6 100644
--- a/cache2go/cache.go
+++ b/engine/cache.go
@@ -1,5 +1,5 @@
//Simple caching library with expiration capabilities
-package cache2go
+package engine
import "sync"
@@ -37,35 +37,35 @@ func init() {
}
}
-func BeginTransaction() {
+func CacheBeginTransaction() {
transactionMux.Lock()
transactionLock = true
transactionON = true
}
-func RollbackTransaction() {
+func CacheRollbackTransaction() {
transactionBuffer = nil
transactionLock = false
transactionON = false
transactionMux.Unlock()
}
-func CommitTransaction() {
+func CacheCommitTransaction() {
transactionON = false
// apply all transactioned items
mux.Lock()
for _, item := range transactionBuffer {
switch item.kind {
case KIND_REM:
- RemKey(item.key)
+ CacheRemKey(item.key)
case KIND_PRF:
- RemPrefixKey(item.key)
+ CacheRemPrefixKey(item.key)
case KIND_ADD:
- Cache(item.key, item.value)
+ CacheSet(item.key, item.value)
case KIND_ADP:
- Push(item.key, item.value)
+ CachePush(item.key, item.value.(string))
case KIND_POP:
- Pop(item.key, item.value)
+ CachePop(item.key, item.value.(string))
}
}
mux.Unlock()
@@ -74,24 +74,25 @@ func CommitTransaction() {
transactionMux.Unlock()
}
-func Save(path string, keys []string) error {
- if !transactionLock {
- mux.Lock()
- defer mux.Unlock()
- }
+func CacheSave(path string, keys []string) error {
+ mux.Lock()
+ defer mux.Unlock()
return cache.Save(path, keys)
}
-func Load(path string, keys []string) error {
+func CacheLoad(path string, keys []string) error {
if !transactionLock {
mux.Lock()
defer mux.Unlock()
}
- return cache.Load(path, keys)
+ if !transactionON {
+ return cache.Load(path, keys)
+ }
+ return nil
}
// The function to be used to cache a key/value pair when expiration is not needed
-func Cache(key string, value interface{}) {
+func CacheSet(key string, value interface{}) {
if !transactionLock {
mux.Lock()
defer mux.Unlock()
@@ -104,8 +105,15 @@ func Cache(key string, value interface{}) {
}
}
+// The function to extract a value for a key that never expire
+func CacheGet(key string) (v interface{}, err error) {
+ mux.RLock()
+ defer mux.RUnlock()
+ return cache.Get(key)
+}
+
// Appends to an existing slice in the cache key
-func Push(key string, value interface{}) {
+func CachePush(key string, value string) {
if !transactionLock {
mux.Lock()
defer mux.Unlock()
@@ -117,14 +125,7 @@ func Push(key string, value interface{}) {
}
}
-// The function to extract a value for a key that never expire
-func Get(key string) (v interface{}, err error) {
- mux.RLock()
- defer mux.RUnlock()
- return cache.Get(key)
-}
-
-func Pop(key string, value interface{}) {
+func CachePop(key string, value string) {
if !transactionLock {
mux.Lock()
defer mux.Unlock()
@@ -136,7 +137,7 @@ func Pop(key string, value interface{}) {
}
}
-func RemKey(key string) {
+func CacheRemKey(key string) {
if !transactionLock {
mux.Lock()
defer mux.Unlock()
@@ -148,7 +149,7 @@ func RemKey(key string) {
}
}
-func RemPrefixKey(prefix string) {
+func CacheRemPrefixKey(prefix string) {
if !transactionLock {
mux.Lock()
defer mux.Unlock()
@@ -161,7 +162,7 @@ func RemPrefixKey(prefix string) {
}
// Delete all keys from cache
-func Flush() {
+func CacheFlush() {
mux.Lock()
defer mux.Unlock()
if DOUBLE_CACHE {
@@ -171,19 +172,19 @@ func Flush() {
}
}
-func CountEntries(prefix string) (result int) {
+func CacheCountEntries(prefix string) (result int) {
mux.RLock()
defer mux.RUnlock()
return cache.CountEntriesForPrefix(prefix)
}
-func GetAllEntries(prefix string) (map[string]interface{}, error) {
+func CacheGetAllEntries(prefix string) (map[string]interface{}, error) {
mux.RLock()
defer mux.RUnlock()
return cache.GetAllForPrefix(prefix)
}
-func GetEntriesKeys(prefix string) (keys []string) {
+func CacheGetEntriesKeys(prefix string) (keys []string) {
mux.RLock()
defer mux.RUnlock()
return cache.GetKeysForPrefix(prefix)
diff --git a/cache2go/store.go b/engine/cache_store.go
similarity index 51%
rename from cache2go/store.go
rename to engine/cache_store.go
index 2ed53d5a4..b7014996b 100644
--- a/cache2go/store.go
+++ b/engine/cache_store.go
@@ -1,8 +1,10 @@
//Simple caching library with expiration capabilities
-package cache2go
+package engine
import (
- "encoding/gob"
+ "bufio"
+ "bytes"
+ "encoding/json"
"log"
"os"
"path/filepath"
@@ -14,9 +16,9 @@ import (
type cacheStore interface {
Put(string, interface{})
- Append(string, interface{})
Get(string) (interface{}, error)
- Pop(string, interface{})
+ Append(string, string)
+ Pop(string, string)
Delete(string)
DeletePrefix(string)
CountEntriesForPrefix(string) int
@@ -29,11 +31,6 @@ type cacheStore interface {
// easy to be counted exported by prefix
type cacheDoubleStore map[string]map[string]interface{}
-type KeyValue struct {
- Key string
- Value interface{}
-}
-
func newDoubleStore() cacheDoubleStore {
return make(cacheDoubleStore)
}
@@ -48,17 +45,6 @@ func (cs cacheDoubleStore) Put(key string, value interface{}) {
mp[key] = value
}
-func (cs cacheDoubleStore) Append(key string, value interface{}) {
- var elements map[interface{}]struct{} // using map for faster check if element is present
- if v, err := cs.Get(key); err == nil {
- elements = v.(map[interface{}]struct{})
- } else {
- elements = make(map[interface{}]struct{})
- }
- elements[value] = struct{}{}
- cache.Put(key, elements)
-}
-
func (cs cacheDoubleStore) Get(key string) (interface{}, error) {
prefix, key := key[:PREFIX_LEN], key[PREFIX_LEN:]
if keyMap, ok := cs[prefix]; ok {
@@ -69,9 +55,20 @@ func (cs cacheDoubleStore) Get(key string) (interface{}, error) {
return nil, utils.ErrNotFound
}
-func (cs cacheDoubleStore) Pop(key string, value interface{}) {
+func (cs cacheDoubleStore) Append(key string, value string) {
+ var elements map[string]struct{} // using map for faster check if element is present
if v, err := cs.Get(key); err == nil {
- elements, ok := v.(map[interface{}]struct{})
+ elements = v.(map[string]struct{})
+ } else {
+ elements = make(map[string]struct{})
+ }
+ elements[value] = struct{}{}
+ cache.Put(key, elements)
+}
+
+func (cs cacheDoubleStore) Pop(key string, value string) {
+ if v, err := cs.Get(key); err == nil {
+ elements, ok := v.(map[string]struct{})
if ok {
delete(elements, value)
if len(elements) > 0 {
@@ -120,7 +117,7 @@ func (cs cacheDoubleStore) GetKeysForPrefix(prefix string) (keys []string) {
return
}
-func (cs cacheDoubleStore) Save(path string, keys []string) error {
+func (cs cacheDoubleStore) Save(path string, prefixes []string) error {
// create a the path
if err := os.MkdirAll(path, 0766); err != nil {
utils.Logger.Info(":" + err.Error())
@@ -128,41 +125,45 @@ func (cs cacheDoubleStore) Save(path string, keys []string) error {
}
var wg sync.WaitGroup
- for _, key := range keys {
- key = key[:PREFIX_LEN]
- value, found := cs[key]
+ for _, prefix := range prefixes {
+ prefix = prefix[:PREFIX_LEN]
+ value, found := cs[prefix]
if !found {
continue
}
wg.Add(1)
- go func(fileName string, data map[string]interface{}) {
+ go func(key string, data map[string]interface{}) {
defer wg.Done()
- dataFile, err := os.Create(filepath.Join(path, fileName) + ".cache")
+ dataFile, err := os.Create(filepath.Join(path, key) + ".cache")
defer dataFile.Close()
if err != nil {
utils.Logger.Info(":" + err.Error())
}
// serialize the data
- dataEncoder := gob.NewEncoder(dataFile)
- log.Print("start: ", fileName)
- if err := dataEncoder.Encode(data); err != nil {
- log.Print("err: ", fileName, err)
- utils.Logger.Info(":" + err.Error())
- } else {
- log.Print("end: ", fileName, err)
+ w := bufio.NewWriter(dataFile)
+ dataEncoder := json.NewEncoder(w)
+ log.Print("start: ", key)
+ for k, v := range data {
+ if err := dataEncoder.Encode(CacheTypeFactory(key, k, v)); err != nil {
+ log.Print("err: ", key, err)
+ utils.Logger.Info(":" + err.Error())
+ break
+ }
}
- }(key, value)
+ log.Print("end: ", key, err)
+ w.Flush()
+ }(prefix, value)
}
wg.Wait()
return nil
}
-func (cs cacheDoubleStore) Load(path string, keys []string) error {
+func (cs cacheDoubleStore) Load(path string, prefixes []string) error {
var wg sync.WaitGroup
- for _, key := range keys {
- key = key[:PREFIX_LEN] // make sure it's only limited to prefix length'
- file := filepath.Join(path, key+".cache")
+ for _, prefix := range prefixes {
+ prefix = prefix[:PREFIX_LEN] // make sure it's only limited to prefix length'
+ file := filepath.Join(path, prefix+".cache")
wg.Add(1)
go func(fileName, key string) {
defer wg.Done()
@@ -175,13 +176,23 @@ func (cs cacheDoubleStore) Load(path string, keys []string) error {
}
val := make(map[string]interface{})
- dataDecoder := gob.NewDecoder(dataFile)
- err = dataDecoder.Decode(&val)
- if err != nil {
- utils.Logger.Info(": " + err.Error())
+ scanner := bufio.NewScanner(dataFile)
+ for scanner.Scan() {
+ dataDecoder := json.NewDecoder(bytes.NewReader(scanner.Bytes()))
+ kv := CacheTypeFactory(key, "", nil)
+ err = dataDecoder.Decode(&kv)
+ if err != nil {
+ log.Printf("err: %v", err)
+ utils.Logger.Info(": " + err.Error())
+ break
+ }
+ val[kv.Key()] = kv.Value()
+ }
+ if err := scanner.Err(); err != nil {
+ utils.Logger.Info(": " + err.Error())
}
cs[key] = val
- }(file, key)
+ }(file, prefix)
}
wg.Wait()
return nil
@@ -208,12 +219,12 @@ func (cs cacheSimpleStore) Put(key string, value interface{}) {
cs.cache[key] = value
}
-func (cs cacheSimpleStore) Append(key string, value interface{}) {
- var elements map[interface{}]struct{}
+func (cs cacheSimpleStore) Append(key string, value string) {
+ var elements map[string]struct{}
if v, err := cs.Get(key); err == nil {
- elements = v.(map[interface{}]struct{})
+ elements = v.(map[string]struct{})
} else {
- elements = make(map[interface{}]struct{})
+ elements = make(map[string]struct{})
}
elements[value] = struct{}{}
cache.Put(key, elements)
@@ -226,9 +237,9 @@ func (cs cacheSimpleStore) Get(key string) (interface{}, error) {
return nil, utils.ErrNotFound
}
-func (cs cacheSimpleStore) Pop(key string, value interface{}) {
+func (cs cacheSimpleStore) Pop(key string, value string) {
if v, err := cs.Get(key); err == nil {
- elements, ok := v.(map[interface{}]struct{})
+ elements, ok := v.(map[string]struct{})
if ok {
delete(elements, value)
if len(elements) > 0 {
@@ -321,3 +332,194 @@ func (cs cacheSimpleStore) Load(path string, keys []string) error {
utils.Logger.Info("simplestore load")
return nil
}
+
+type cacheKeyValue interface {
+ Key() string
+ Value() interface{}
+}
+
+type mapKeyValue struct {
+ K string
+ V map[string]struct{}
+}
+
+func (mkv *mapKeyValue) Key() string {
+ return mkv.K
+}
+
+func (mkv *mapKeyValue) Value() interface{} {
+ return mkv.V
+}
+
+type rpKeyValue struct {
+ K string
+ V *RatingPlan
+}
+
+func (mkv *rpKeyValue) Key() string {
+ return mkv.K
+}
+
+func (mkv *rpKeyValue) Value() interface{} {
+ return mkv.V
+}
+
+type rpfKeyValue struct {
+ K string
+ V *RatingProfile
+}
+
+func (mkv *rpfKeyValue) Key() string {
+ return mkv.K
+}
+
+func (mkv *rpfKeyValue) Value() interface{} {
+ return mkv.V
+}
+
+type lcrKeyValue struct {
+ K string
+ V *LCR
+}
+
+func (mkv *lcrKeyValue) Key() string {
+ return mkv.K
+}
+
+func (mkv *lcrKeyValue) Value() interface{} {
+ return mkv.V
+}
+
+type dcKeyValue struct {
+ K string
+ V *utils.DerivedChargers
+}
+
+func (mkv *dcKeyValue) Key() string {
+ return mkv.K
+}
+
+func (mkv *dcKeyValue) Value() interface{} {
+ return mkv.V
+}
+
+type acsKeyValue struct {
+ K string
+ V Actions
+}
+
+func (mkv *acsKeyValue) Key() string {
+ return mkv.K
+}
+
+func (mkv *acsKeyValue) Value() interface{} {
+ return mkv.V
+}
+
+type aplKeyValue struct {
+ K string
+ V *ActionPlan
+}
+
+func (mkv *aplKeyValue) Key() string {
+ return mkv.K
+}
+
+func (mkv *aplKeyValue) Value() interface{} {
+ return mkv.V
+}
+
+type sgKeyValue struct {
+ K string
+ V *SharedGroup
+}
+
+func (mkv *sgKeyValue) Key() string {
+ return mkv.K
+}
+
+func (mkv *sgKeyValue) Value() interface{} {
+ return mkv.V
+}
+
+type alsKeyValue struct {
+ K string
+ V AliasValues
+}
+
+func (mkv *alsKeyValue) Key() string {
+ return mkv.K
+}
+
+func (mkv *alsKeyValue) Value() interface{} {
+ return mkv.V
+}
+
+type loadKeyValue struct {
+ K string
+ V []*utils.LoadInstance
+}
+
+func (mkv *loadKeyValue) Key() string {
+ return mkv.K
+}
+
+func (mkv *loadKeyValue) Value() interface{} {
+ return mkv.V
+}
+
+func CacheTypeFactory(prefix string, key string, value interface{}) cacheKeyValue {
+ switch prefix {
+ case utils.DESTINATION_PREFIX:
+ if value != nil {
+ return &mapKeyValue{key, value.(map[string]struct{})}
+ }
+ return &mapKeyValue{"", make(map[string]struct{})}
+ case utils.RATING_PLAN_PREFIX:
+ if value != nil {
+ return &rpKeyValue{key, value.(*RatingPlan)}
+ }
+ return &rpfKeyValue{"", &RatingProfile{}}
+ case utils.RATING_PROFILE_PREFIX:
+ if value != nil {
+ return &rpfKeyValue{key, value.(*RatingProfile)}
+ }
+ return &rpfKeyValue{"", &RatingProfile{}}
+ case utils.LCR_PREFIX:
+ if value != nil {
+ return &lcrKeyValue{key, value.(*LCR)}
+ }
+ return &lcrKeyValue{"", &LCR{}}
+ case utils.DERIVEDCHARGERS_PREFIX:
+ if value != nil {
+ return &dcKeyValue{key, value.(*utils.DerivedChargers)}
+ }
+ return &dcKeyValue{"", &utils.DerivedChargers{}}
+ case utils.ACTION_PREFIX:
+ if value != nil {
+ return &acsKeyValue{key, value.(Actions)}
+ }
+ return &acsKeyValue{"", Actions{}}
+ case utils.ACTION_PLAN_PREFIX:
+ if value != nil {
+ return &aplKeyValue{key, value.(*ActionPlan)}
+ }
+ return &aplKeyValue{"", &ActionPlan{}}
+ case utils.SHARED_GROUP_PREFIX:
+ if value != nil {
+ return &sgKeyValue{key, value.(*SharedGroup)}
+ }
+ return &sgKeyValue{"", &SharedGroup{}}
+ case utils.ALIASES_PREFIX:
+ if value != nil {
+ return &alsKeyValue{key, value.(AliasValues)}
+ }
+ return &alsKeyValue{"", AliasValues{}}
+ case utils.LOADINST_KEY[:PREFIX_LEN]:
+ if value != nil {
+ return &loadKeyValue{key, value.([]*utils.LoadInstance)}
+ }
+ return &loadKeyValue{"", make([]*utils.LoadInstance, 0)}
+ }
+ return nil
+}
diff --git a/engine/cache_test.go b/engine/cache_test.go
new file mode 100644
index 000000000..705c39bfb
--- /dev/null
+++ b/engine/cache_test.go
@@ -0,0 +1,120 @@
+package engine
+
+import "testing"
+
+func TestRemKey(t *testing.T) {
+ CacheSet("t11_mm", "test")
+ if t1, err := CacheGet("t11_mm"); err != nil || t1 != "test" {
+ t.Error("Error setting cache: ", err, t1)
+ }
+ CacheRemKey("t11_mm")
+ if t1, err := CacheGet("t11_mm"); err == nil || t1 == "test" {
+ t.Error("Error removing cached key")
+ }
+}
+
+func TestTransaction(t *testing.T) {
+ CacheBeginTransaction()
+ CacheSet("t11_mm", "test")
+ if t1, err := CacheGet("t11_mm"); err == nil || t1 == "test" {
+ t.Error("Error in transaction cache")
+ }
+ CacheSet("t12_mm", "test")
+ CacheRemKey("t11_mm")
+ CacheCommitTransaction()
+ if t1, err := CacheGet("t12_mm"); err != nil || t1 != "test" {
+ t.Error("Error commiting transaction")
+ }
+ if t1, err := CacheGet("t11_mm"); err == nil || 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, err := CacheGet("t21_mm"); err == nil || t1 == "test" {
+ t.Error("Error commiting transaction")
+ }
+ if t1, err := CacheGet("t21_nn"); err == nil || t1 == "test" {
+ t.Error("Error in transaction cache")
+ }
+}
+
+func TestTransactionRollback(t *testing.T) {
+ CacheBeginTransaction()
+ CacheSet("t31_mm", "test")
+ if t1, err := CacheGet("t31_mm"); err == nil || t1 == "test" {
+ t.Error("Error in transaction cache")
+ }
+ CacheSet("t32_mm", "test")
+ CacheRollbackTransaction()
+ if t1, err := CacheGet("t32_mm"); err == nil || t1 == "test" {
+ t.Error("Error commiting transaction")
+ }
+ if t1, err := CacheGet("t31_mm"); err == nil || 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, err := CacheGet("t41_mm"); err != nil || t1 != "test" {
+ t.Error("Error commiting transaction")
+ }
+ if t1, err := CacheGet("t41_nn"); err != nil || t1 != "test" {
+ t.Error("Error in transaction cache")
+ }
+}
+
+func TestCacheRemPrefixKey(t *testing.T) {
+ CacheSet("xxx_t1", "test")
+ CacheSet("yyy_t1", "test")
+ CacheRemPrefixKey("xxx_")
+ _, errX := CacheGet("xxx_t1")
+ _, errY := CacheGet("yyy_t1")
+ if errX == nil || errY != nil {
+ t.Error("Error removing prefix: ", errX, errY)
+ }
+}
+
+func TestCachePush(t *testing.T) {
+ CachePush("ccc_t1", "1")
+ CachePush("ccc_t1", "2")
+ v, err := CacheGet("ccc_t1")
+ if err != nil || len(v.(map[string]struct{})) != 2 {
+ t.Error("Error in cache push: ", v)
+ }
+}
+
+func TestCachePop(t *testing.T) {
+ CachePush("ccc_t1", "1")
+ CachePush("ccc_t1", "2")
+ v, err := CacheGet("ccc_t1")
+ if err != nil || len(v.(map[string]struct{})) != 2 {
+ t.Error("Error in cache push: ", v)
+ }
+ CachePop("ccc_t1", "1")
+ v, err = CacheGet("ccc_t1")
+ if err != nil || len(v.(map[string]struct{})) != 1 {
+ t.Error("Error in cache pop: ", v)
+ }
+}
+
+/*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_"))
+ }
+}*/
diff --git a/engine/callcost.go b/engine/callcost.go
index c482f2b55..8f84f9baf 100644
--- a/engine/callcost.go
+++ b/engine/callcost.go
@@ -21,7 +21,6 @@ import (
"errors"
"time"
- "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
)
@@ -236,8 +235,8 @@ 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, err := cache2go.Get(utils.DESTINATION_PREFIX + p); err == nil {
- destIds := x.(map[interface{}]struct{})
+ if x, err := CacheGet(utils.DESTINATION_PREFIX + p); err == nil {
+ destIds := x.(map[string]struct{})
for filterDestID := range *bf.DestinationIDs {
if _, ok := destIds[filterDestID]; ok {
foundMatchingDestID = true
diff --git a/engine/calldesc.go b/engine/calldesc.go
index d62a0005e..d2a40aab3 100644
--- a/engine/calldesc.go
+++ b/engine/calldesc.go
@@ -27,7 +27,6 @@ import (
"strings"
"time"
- "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
"github.com/cgrates/rpcclient"
)
@@ -890,7 +889,7 @@ func (cd *CallDescriptor) RefundRounding() error {
}
func (cd *CallDescriptor) FlushCache() (err error) {
- cache2go.Flush()
+ CacheFlush()
ratingStorage.CacheRatingAll()
accountingStorage.CacheAccountingAll()
return nil
@@ -1038,7 +1037,7 @@ func (cd *CallDescriptor) GetLCR(stats rpcclient.RpcClientConnection, p *utils.P
}
ratingProfileSearchKey := utils.ConcatenatedKey(lcr.Direction, lcr.Tenant, lcrCost.Entry.RPCategory)
//log.Print("KEY: ", ratingProfileSearchKey)
- suppliers := cache2go.GetEntriesKeys(utils.RATING_PROFILE_PREFIX + ratingProfileSearchKey)
+ suppliers := CacheGetEntriesKeys(utils.RATING_PROFILE_PREFIX + ratingProfileSearchKey)
for _, supplier := range suppliers {
//log.Print("Supplier: ", supplier)
split := strings.Split(supplier, ":")
diff --git a/engine/cdrs.go b/engine/cdrs.go
index d296df1a0..0dee7f23f 100644
--- a/engine/cdrs.go
+++ b/engine/cdrs.go
@@ -28,7 +28,6 @@ import (
"strings"
"time"
- "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/utils"
"github.com/cgrates/rpcclient"
@@ -98,20 +97,20 @@ type CdrServer struct {
aliases rpcclient.RpcClientConnection
stats rpcclient.RpcClientConnection
guard *GuardianLock
- responseCache *cache2go.ResponseCache
+ responseCache *ResponseCache
}
func (self *CdrServer) Timezone() string {
return self.cgrCfg.DefaultTimezone
}
func (self *CdrServer) SetTimeToLive(timeToLive time.Duration, out *int) error {
- self.responseCache = cache2go.NewResponseCache(timeToLive)
+ self.responseCache = NewResponseCache(timeToLive)
return nil
}
-func (self *CdrServer) getCache() *cache2go.ResponseCache {
+func (self *CdrServer) getCache() *ResponseCache {
if self.responseCache == nil {
- self.responseCache = cache2go.NewResponseCache(0)
+ self.responseCache = NewResponseCache(0)
}
return self.responseCache
}
@@ -501,10 +500,10 @@ func (self *CdrServer) V1ProcessCDR(cdr *CDR, reply *string) error {
return item.Err
}
if err := self.LocalProcessCdr(cdr); err != nil {
- self.getCache().Cache(cacheKey, &cache2go.CacheItem{Err: err})
+ self.getCache().Cache(cacheKey, &CacheItem{Err: err})
return utils.NewErrServerError(err)
}
- self.getCache().Cache(cacheKey, &cache2go.CacheItem{Value: utils.OK})
+ self.getCache().Cache(cacheKey, &CacheItem{Value: utils.OK})
*reply = utils.OK
return nil
}
diff --git a/engine/cdrstats.go b/engine/cdrstats.go
index 94d17cf51..159bb4464 100644
--- a/engine/cdrstats.go
+++ b/engine/cdrstats.go
@@ -22,7 +22,6 @@ import (
"reflect"
"time"
- "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/utils"
)
@@ -124,10 +123,10 @@ 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, err := cache2go.Get(utils.DESTINATION_PREFIX + p); err == nil {
- destIds := x.(map[interface{}]struct{})
+ if x, err := CacheGet(utils.DESTINATION_PREFIX + p); err == nil {
+ destIds := x.(map[string]struct{})
for idID := range destIds {
- if utils.IsSliceMember(cs.DestinationIds, idID.(string)) {
+ if utils.IsSliceMember(cs.DestinationIds, idID) {
found = true
break
}
diff --git a/engine/destinations.go b/engine/destinations.go
index ae60cf187..d2880ede3 100644
--- a/engine/destinations.go
+++ b/engine/destinations.go
@@ -22,7 +22,6 @@ import (
"encoding/json"
"strings"
- "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
"github.com/cgrates/cgrates/history"
@@ -75,8 +74,8 @@ 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, err := cache2go.Get(utils.DESTINATION_PREFIX + prefix); err == nil {
- _, found := cached.(map[interface{}]struct{})[destId]
+ if cached, err := CacheGet(utils.DESTINATION_PREFIX + prefix); err == nil {
+ _, found := cached.(map[string]struct{})[destId]
return found
}
return false
@@ -84,18 +83,18 @@ func CachedDestHasPrefix(destId, prefix string) bool {
func CleanStalePrefixes(destIds []string) {
utils.Logger.Info("Cleaning stale dest prefixes: " + utils.ToJSON(destIds))
- prefixMap, err := cache2go.GetAllEntries(utils.DESTINATION_PREFIX)
+ prefixMap, err := CacheGetAllEntries(utils.DESTINATION_PREFIX)
if err != nil {
return
}
for prefix, idIDs := range prefixMap {
- dIDs := idIDs.(map[interface{}]struct{})
+ dIDs := idIDs.(map[string]struct{})
changed := false
for _, searchedDID := range destIds {
if _, found := dIDs[searchedDID]; found {
if len(dIDs) == 1 {
// remove de prefix from cache
- cache2go.RemKey(utils.DESTINATION_PREFIX + prefix)
+ CacheRemKey(utils.DESTINATION_PREFIX + prefix)
} else {
// delete the destination from list and put the new list in chache
delete(dIDs, searchedDID)
@@ -104,7 +103,7 @@ func CleanStalePrefixes(destIds []string) {
}
}
if changed {
- cache2go.Cache(utils.DESTINATION_PREFIX+prefix, dIDs)
+ CacheSet(utils.DESTINATION_PREFIX+prefix, dIDs)
}
}
}
diff --git a/engine/destinations_test.go b/engine/destinations_test.go
index ec0ba399b..fd1960265 100644
--- a/engine/destinations_test.go
+++ b/engine/destinations_test.go
@@ -21,7 +21,6 @@ package engine
import (
"encoding/json"
- "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
"testing"
@@ -83,7 +82,7 @@ func TestDestinationGetExists(t *testing.T) {
func TestDestinationGetExistsCache(t *testing.T) {
ratingStorage.GetDestination("NAT")
- if _, err := cache2go.Get(utils.DESTINATION_PREFIX + "0256"); err != nil {
+ if _, err := CacheGet(utils.DESTINATION_PREFIX + "0256"); err != nil {
t.Error("Destination not cached:", err)
}
}
@@ -97,7 +96,7 @@ func TestDestinationGetNotExists(t *testing.T) {
func TestDestinationGetNotExistsCache(t *testing.T) {
ratingStorage.GetDestination("not existing")
- if d, err := cache2go.Get("not existing"); err == nil {
+ if d, err := CacheGet("not existing"); err == nil {
t.Error("Bad destination cached: ", d)
}
}
@@ -128,17 +127,17 @@ func TestNonCachedDestWrongPrefix(t *testing.T) {
func TestCleanStalePrefixes(t *testing.T) {
x := struct{}{}
- cache2go.Cache(utils.DESTINATION_PREFIX+"1", map[interface{}]struct{}{"D1": x, "D2": x})
- cache2go.Cache(utils.DESTINATION_PREFIX+"2", map[interface{}]struct{}{"D1": x})
- cache2go.Cache(utils.DESTINATION_PREFIX+"3", map[interface{}]struct{}{"D2": x})
+ 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})
CleanStalePrefixes([]string{"D1"})
- if r, err := cache2go.Get(utils.DESTINATION_PREFIX + "1"); err != nil || len(r.(map[interface{}]struct{})) != 1 {
+ if r, err := CacheGet(utils.DESTINATION_PREFIX + "1"); err != nil || len(r.(map[string]struct{})) != 1 {
t.Error("Error cleaning stale destination ids", r)
}
- if r, err := cache2go.Get(utils.DESTINATION_PREFIX + "2"); err == nil {
+ if r, err := CacheGet(utils.DESTINATION_PREFIX + "2"); err == nil {
t.Error("Error removing stale prefix: ", r)
}
- if r, err := cache2go.Get(utils.DESTINATION_PREFIX + "3"); err != nil || len(r.(map[interface{}]struct{})) != 1 {
+ if r, err := CacheGet(utils.DESTINATION_PREFIX + "3"); err != nil || 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 e845ac1dd..22051e04e 100644
--- a/engine/handler_derivedcharging.go
+++ b/engine/handler_derivedcharging.go
@@ -19,7 +19,6 @@ along with this program. If not, see
package engine
import (
- "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
)
@@ -48,10 +47,10 @@ func DerivedChargersMatchesDest(dcs *utils.DerivedChargers, dest string) bool {
}
// check destination ids
for _, p := range utils.SplitPrefix(dest, MIN_PREFIX_MATCH) {
- if x, err := cache2go.Get(utils.DESTINATION_PREFIX + p); err == nil {
- destIds := x.(map[interface{}]struct{})
+ if x, err := CacheGet(utils.DESTINATION_PREFIX + p); err == nil {
+ destIds := x.(map[string]struct{})
for dId := range destIds {
- includeDest, found := dcs.DestinationIDs[dId.(string)]
+ includeDest, found := dcs.DestinationIDs[dId]
if found {
return includeDest
}
diff --git a/engine/lcr.go b/engine/lcr.go
index 2a50c6003..d0df434a4 100644
--- a/engine/lcr.go
+++ b/engine/lcr.go
@@ -26,7 +26,6 @@ import (
"strings"
"time"
- "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/utils"
)
@@ -274,11 +273,10 @@ 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, err := cache2go.Get(utils.DESTINATION_PREFIX + p); err == nil {
+ if x, err := CacheGet(utils.DESTINATION_PREFIX + p); err == nil {
- destIds := x.(map[interface{}]struct{})
- for idId := range destIds {
- dId := idId.(string)
+ destIds := x.(map[string]struct{})
+ for dId := range destIds {
for _, entry := range lcra.Entries {
if entry.DestinationId == dId {
entry.precision = len(p)
diff --git a/engine/ratingprofile.go b/engine/ratingprofile.go
index d0ec02be5..f3e3c8a5f 100644
--- a/engine/ratingprofile.go
+++ b/engine/ratingprofile.go
@@ -25,7 +25,6 @@ import (
"strings"
"time"
- "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/history"
"github.com/cgrates/cgrates/utils"
)
@@ -174,11 +173,10 @@ func (rpf *RatingProfile) GetRatingPlansForPrefix(cd *CallDescriptor) (err error
}
} else {
for _, p := range utils.SplitPrefix(cd.Destination, MIN_PREFIX_MATCH) {
- if x, err := cache2go.Get(utils.DESTINATION_PREFIX + p); err == nil {
- destIds := x.(map[interface{}]struct{})
+ if x, err := CacheGet(utils.DESTINATION_PREFIX + p); err == nil {
+ destIds := x.(map[string]struct{})
var bestWeight float64
- for idID := range destIds {
- dID := idID.(string)
+ for dID := range destIds {
if _, ok := rpl.DestinationRates[dID]; ok {
ril := rpl.RateIntervalList(dID)
currentWeight := ril.GetWeight()
diff --git a/engine/responder.go b/engine/responder.go
index f85daa733..906528970 100644
--- a/engine/responder.go
+++ b/engine/responder.go
@@ -28,7 +28,6 @@ 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 +52,17 @@ type Responder struct {
Timeout time.Duration
Timezone string
cnt int64
- responseCache *cache2go.ResponseCache
+ responseCache *ResponseCache
}
func (rs *Responder) SetTimeToLive(timeToLive time.Duration, out *int) error {
- rs.responseCache = cache2go.NewResponseCache(timeToLive)
+ rs.responseCache = NewResponseCache(timeToLive)
return nil
}
-func (rs *Responder) getCache() *cache2go.ResponseCache {
+func (rs *Responder) getCache() *ResponseCache {
if rs.responseCache == nil {
- rs.responseCache = cache2go.NewResponseCache(0)
+ rs.responseCache = NewResponseCache(0)
}
return rs.responseCache
}
@@ -179,7 +178,7 @@ func (rs *Responder) MaxDebit(arg *CallDescriptor, reply *CallCost) (err error)
} else {
r, e := arg.MaxDebit()
if e != nil {
- rs.getCache().Cache(cacheKey, &cache2go.CacheItem{
+ rs.getCache().Cache(cacheKey, &CacheItem{
Err: e,
})
return e
@@ -187,7 +186,7 @@ func (rs *Responder) MaxDebit(arg *CallDescriptor, reply *CallCost) (err error)
*reply = *r
}
}
- rs.getCache().Cache(cacheKey, &cache2go.CacheItem{
+ rs.getCache().Cache(cacheKey, &CacheItem{
Value: reply,
Err: err,
})
@@ -218,7 +217,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, &cache2go.CacheItem{
+ rs.getCache().Cache(cacheKey, &CacheItem{
Err: err,
})
return err
@@ -229,7 +228,7 @@ func (rs *Responder) RefundIncrements(arg *CallDescriptor, reply *float64) (err
} else {
err = arg.RefundIncrements()
}
- rs.getCache().Cache(cacheKey, &cache2go.CacheItem{
+ rs.getCache().Cache(cacheKey, &CacheItem{
Value: reply,
Err: err,
})
@@ -260,7 +259,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, &cache2go.CacheItem{
+ rs.getCache().Cache(cacheKey, &CacheItem{
Err: err,
})
return err
@@ -271,7 +270,7 @@ func (rs *Responder) RefundRounding(arg *CallDescriptor, reply *float64) (err er
} else {
err = arg.RefundRounding()
}
- rs.getCache().Cache(cacheKey, &cache2go.CacheItem{
+ rs.getCache().Cache(cacheKey, &CacheItem{
Value: reply,
Err: err,
})
@@ -324,7 +323,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, &cache2go.CacheItem{Err: err})
+ rs.getCache().Cache(cacheKey, &CacheItem{Err: err})
return err
}
// replace aliases
@@ -338,7 +337,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, &cache2go.CacheItem{Err: err})
+ rs.getCache().Cache(cacheKey, &CacheItem{Err: err})
return err
}
@@ -347,7 +346,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, &cache2go.CacheItem{Err: err})
+ rs.getCache().Cache(cacheKey, &CacheItem{Err: err})
return err
}
dcs, _ = dcs.AppendDefaultRun()
@@ -368,12 +367,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, &cache2go.CacheItem{Err: err})
+ rs.getCache().Cache(cacheKey, &CacheItem{Err: err})
return err
}
usage, err := ev.GetDuration(utils.META_DEFAULT)
if err != nil {
- rs.getCache().Cache(cacheKey, &cache2go.CacheItem{Err: err})
+ rs.getCache().Cache(cacheKey, &CacheItem{Err: err})
return err
}
if usage == 0 {
@@ -396,7 +395,7 @@ func (rs *Responder) GetDerivedMaxSessionTime(ev *CDR, reply *float64) error {
err = rs.GetMaxSessionTime(cd, &remainingDuration)
if err != nil {
*reply = 0
- rs.getCache().Cache(cacheKey, &cache2go.CacheItem{Err: err})
+ rs.getCache().Cache(cacheKey, &CacheItem{Err: err})
return err
}
if utils.IsSliceMember([]string{utils.META_POSTPAID, utils.POSTPAID}, ev.GetReqType(dc.RequestTypeField)) {
@@ -410,7 +409,7 @@ func (rs *Responder) GetDerivedMaxSessionTime(ev *CDR, reply *float64) error {
maxCallDuration = remainingDuration
}
}
- rs.getCache().Cache(cacheKey, &cache2go.CacheItem{Value: maxCallDuration})
+ rs.getCache().Cache(cacheKey, &CacheItem{Value: maxCallDuration})
*reply = maxCallDuration
return nil
}
@@ -453,7 +452,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, &cache2go.CacheItem{
+ rs.getCache().Cache(cacheKey, &CacheItem{
Err: err,
})
return err
@@ -467,12 +466,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, &cache2go.CacheItem{Err: err})
+ rs.getCache().Cache(cacheKey, &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, &cache2go.CacheItem{Err: err})
+ rs.getCache().Cache(cacheKey, &CacheItem{Err: err})
return errors.New("Error parsing answer event end time")
}
extraFields := ev.GetExtraFields()
@@ -499,7 +498,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, &cache2go.CacheItem{Value: sRuns})
+ rs.getCache().Cache(cacheKey, &CacheItem{Value: sRuns})
return nil
}
@@ -540,12 +539,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, &cache2go.CacheItem{Err: err})
+ rs.getCache().Cache(cacheKey, &CacheItem{Err: err})
return err
}
lcrCost, err := attrs.CallDescriptor.GetLCR(rs.Stats, attrs.Paginator)
if err != nil {
- rs.getCache().Cache(cacheKey, &cache2go.CacheItem{Err: err})
+ rs.getCache().Cache(cacheKey, &CacheItem{Err: err})
return err
}
if lcrCost.Entry != nil && lcrCost.Entry.Strategy == LCR_STRATEGY_LOAD {
@@ -553,7 +552,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, &cache2go.CacheItem{Value: lcrCost})
+ rs.getCache().Cache(cacheKey, &CacheItem{Value: lcrCost})
*reply = *lcrCost
return nil
}
diff --git a/cache2go/response_cache.go b/engine/response_cache.go
similarity index 99%
rename from cache2go/response_cache.go
rename to engine/response_cache.go
index c7631cc57..38aa9aa57 100644
--- a/cache2go/response_cache.go
+++ b/engine/response_cache.go
@@ -1,4 +1,4 @@
-package cache2go
+package engine
import (
"errors"
diff --git a/cache2go/response_cache_test.go b/engine/response_cache_test.go
similarity index 97%
rename from cache2go/response_cache_test.go
rename to engine/response_cache_test.go
index 40dc20722..d80dd1d45 100644
--- a/cache2go/response_cache_test.go
+++ b/engine/response_cache_test.go
@@ -1,4 +1,4 @@
-package cache2go
+package engine
import (
"testing"
diff --git a/engine/storage_map.go b/engine/storage_map.go
index be821d54d..837a4de4b 100644
--- a/engine/storage_map.go
+++ b/engine/storage_map.go
@@ -29,7 +29,6 @@ import (
"strings"
"time"
- "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
)
@@ -69,7 +68,7 @@ func (ms *MapStorage) GetKeysForPrefix(prefix string, skipCache bool) ([]string,
}
return keysForPrefix, nil
}
- return cache2go.GetEntriesKeys(prefix), nil
+ return CacheGetEntriesKeys(prefix), nil
}
func (ms *MapStorage) CacheRatingAll() error {
@@ -117,91 +116,91 @@ func (ms *MapStorage) CacheRatingPrefixValues(prefixes map[string][]string) erro
}
func (ms *MapStorage) cacheRating(dKeys, rpKeys, rpfKeys, lcrKeys, dcsKeys, actKeys, aplKeys, shgKeys []string) error {
- cache2go.BeginTransaction()
- if dKeys == nil || (float64(cache2go.CountEntries(utils.DESTINATION_PREFIX))*utils.DESTINATIONS_LOAD_THRESHOLD < float64(len(dKeys))) {
- cache2go.RemPrefixKey(utils.DESTINATION_PREFIX)
+ CacheBeginTransaction()
+ if dKeys == nil || (float64(CacheCountEntries(utils.DESTINATION_PREFIX))*utils.DESTINATIONS_LOAD_THRESHOLD < float64(len(dKeys))) {
+ CacheRemPrefixKey(utils.DESTINATION_PREFIX)
} else {
CleanStalePrefixes(dKeys)
}
if rpKeys == nil {
- cache2go.RemPrefixKey(utils.RATING_PLAN_PREFIX)
+ CacheRemPrefixKey(utils.RATING_PLAN_PREFIX)
}
if rpfKeys == nil {
- cache2go.RemPrefixKey(utils.RATING_PROFILE_PREFIX)
+ CacheRemPrefixKey(utils.RATING_PROFILE_PREFIX)
}
if lcrKeys == nil {
- cache2go.RemPrefixKey(utils.LCR_PREFIX)
+ CacheRemPrefixKey(utils.LCR_PREFIX)
}
if dcsKeys == nil {
- cache2go.RemPrefixKey(utils.DERIVEDCHARGERS_PREFIX)
+ CacheRemPrefixKey(utils.DERIVEDCHARGERS_PREFIX)
}
if actKeys == nil {
- cache2go.RemPrefixKey(utils.ACTION_PREFIX) // Forced until we can fine tune it
+ CacheRemPrefixKey(utils.ACTION_PREFIX) // Forced until we can fine tune it
}
if aplKeys == nil {
- cache2go.RemPrefixKey(utils.ACTION_PLAN_PREFIX)
+ CacheRemPrefixKey(utils.ACTION_PLAN_PREFIX)
}
if shgKeys == nil {
- cache2go.RemPrefixKey(utils.SHARED_GROUP_PREFIX) // Forced until we can fine tune it
+ CacheRemPrefixKey(utils.SHARED_GROUP_PREFIX) // Forced until we can fine tune it
}
for k, _ := range ms.dict {
if strings.HasPrefix(k, utils.DESTINATION_PREFIX) {
if _, err := ms.GetDestination(k[len(utils.DESTINATION_PREFIX):]); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return err
}
}
if strings.HasPrefix(k, utils.RATING_PLAN_PREFIX) {
- cache2go.RemKey(k)
+ CacheRemKey(k)
if _, err := ms.GetRatingPlan(k[len(utils.RATING_PLAN_PREFIX):], true); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return err
}
}
if strings.HasPrefix(k, utils.RATING_PROFILE_PREFIX) {
- cache2go.RemKey(k)
+ CacheRemKey(k)
if _, err := ms.GetRatingProfile(k[len(utils.RATING_PROFILE_PREFIX):], true); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return err
}
}
if strings.HasPrefix(k, utils.LCR_PREFIX) {
- cache2go.RemKey(k)
+ CacheRemKey(k)
if _, err := ms.GetLCR(k[len(utils.LCR_PREFIX):], true); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return err
}
}
if strings.HasPrefix(k, utils.DERIVEDCHARGERS_PREFIX) {
- cache2go.RemKey(k)
+ CacheRemKey(k)
if _, err := ms.GetDerivedChargers(k[len(utils.DERIVEDCHARGERS_PREFIX):], true); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return err
}
}
if strings.HasPrefix(k, utils.ACTION_PREFIX) {
- cache2go.RemKey(k)
+ CacheRemKey(k)
if _, err := ms.GetActions(k[len(utils.ACTION_PREFIX):], true); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return err
}
}
if strings.HasPrefix(k, utils.ACTION_PLAN_PREFIX) {
- cache2go.RemKey(k)
+ CacheRemKey(k)
if _, err := ms.GetActionPlan(k[len(utils.ACTION_PLAN_PREFIX):], true); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return err
}
}
if strings.HasPrefix(k, utils.SHARED_GROUP_PREFIX) {
- cache2go.RemKey(k)
+ CacheRemKey(k)
if _, err := ms.GetSharedGroup(k[len(utils.SHARED_GROUP_PREFIX):], true); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return err
}
}
}
- cache2go.CommitTransaction()
+ CacheCommitTransaction()
return nil
}
@@ -236,27 +235,27 @@ func (ms *MapStorage) CacheAccountingPrefixValues(prefixes map[string][]string)
}
func (ms *MapStorage) cacheAccounting(alsKeys []string) error {
- cache2go.BeginTransaction()
+ CacheBeginTransaction()
if alsKeys == nil {
- cache2go.RemPrefixKey(utils.ALIASES_PREFIX) // Forced until we can fine tune it
+ CacheRemPrefixKey(utils.ALIASES_PREFIX) // Forced until we can fine tune it
}
for k, _ := range ms.dict {
if strings.HasPrefix(k, utils.ALIASES_PREFIX) {
// check if it already exists
// to remove reverse cache keys
- if avs, err := cache2go.Get(k); err == nil && avs != nil {
+ if avs, err := CacheGet(k); err == nil && avs != nil {
al := &Alias{Values: avs.(AliasValues)}
al.SetId(k[len(utils.ALIASES_PREFIX):])
al.RemoveReverseCache()
}
- cache2go.RemKey(k)
+ CacheRemKey(k)
if _, err := ms.GetAlias(k[len(utils.ALIASES_PREFIX):], true); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return err
}
}
}
- cache2go.CommitTransaction()
+ CacheCommitTransaction()
return nil
}
@@ -277,7 +276,7 @@ func (ms *MapStorage) GetRatingPlan(key string, skipCache bool) (rp *RatingPlan,
defer ms.mu.RUnlock()
key = utils.RATING_PLAN_PREFIX + key
if !skipCache {
- if x, err := cache2go.Get(key); err == nil {
+ if x, err := CacheGet(key); err == nil {
return x.(*RatingPlan), nil
} else {
return nil, err
@@ -296,7 +295,7 @@ func (ms *MapStorage) GetRatingPlan(key string, skipCache bool) (rp *RatingPlan,
r.Close()
rp = new(RatingPlan)
err = ms.ms.Unmarshal(out, rp)
- cache2go.Cache(key, rp)
+ CacheSet(key, rp)
} else {
return nil, utils.ErrNotFound
}
@@ -324,7 +323,7 @@ func (ms *MapStorage) GetRatingProfile(key string, skipCache bool) (rpf *RatingP
defer ms.mu.RUnlock()
key = utils.RATING_PROFILE_PREFIX + key
if !skipCache {
- if x, err := cache2go.Get(key); err == nil {
+ if x, err := CacheGet(key); err == nil {
return x.(*RatingProfile), nil
} else {
return nil, err
@@ -334,7 +333,7 @@ func (ms *MapStorage) GetRatingProfile(key string, skipCache bool) (rpf *RatingP
rpf = new(RatingProfile)
err = ms.ms.Unmarshal(values, rpf)
- cache2go.Cache(key, rpf)
+ CacheSet(key, rpf)
} else {
return nil, utils.ErrNotFound
}
@@ -359,7 +358,7 @@ func (ms *MapStorage) RemoveRatingProfile(key string) (err error) {
for k := range ms.dict {
if strings.HasPrefix(k, key) {
delete(ms.dict, key)
- cache2go.RemKey(k)
+ CacheRemKey(k)
response := 0
rpf := &RatingProfile{Id: key}
if historyScribe != nil {
@@ -375,7 +374,7 @@ func (ms *MapStorage) GetLCR(key string, skipCache bool) (lcr *LCR, err error) {
defer ms.mu.RUnlock()
key = utils.LCR_PREFIX + key
if !skipCache {
- if x, err := cache2go.Get(key); err == nil {
+ if x, err := CacheGet(key); err == nil {
return x.(*LCR), nil
} else {
return nil, err
@@ -383,7 +382,7 @@ func (ms *MapStorage) GetLCR(key string, skipCache bool) (lcr *LCR, err error) {
}
if values, ok := ms.dict[key]; ok {
err = ms.ms.Unmarshal(values, &lcr)
- cache2go.Cache(key, lcr)
+ CacheSet(key, lcr)
} else {
return nil, utils.ErrNotFound
}
@@ -417,7 +416,7 @@ func (ms *MapStorage) GetDestination(key string) (dest *Destination, err error)
err = ms.ms.Unmarshal(out, dest)
// create optimized structure
for _, p := range dest.Prefixes {
- cache2go.Push(utils.DESTINATION_PREFIX+p, dest.Id)
+ CachePush(utils.DESTINATION_PREFIX+p, dest.Id)
}
} else {
return nil, utils.ErrNotFound
@@ -450,7 +449,7 @@ func (ms *MapStorage) GetActions(key string, skipCache bool) (as Actions, err er
defer ms.mu.RUnlock()
key = utils.ACTION_PREFIX + key
if !skipCache {
- if x, err := cache2go.Get(key); err == nil {
+ if x, err := CacheGet(key); err == nil {
return x.(Actions), nil
} else {
return nil, err
@@ -458,7 +457,7 @@ func (ms *MapStorage) GetActions(key string, skipCache bool) (as Actions, err er
}
if values, ok := ms.dict[key]; ok {
err = ms.ms.Unmarshal(values, &as)
- cache2go.Cache(key, as)
+ CacheSet(key, as)
} else {
return nil, utils.ErrNotFound
}
@@ -485,7 +484,7 @@ func (ms *MapStorage) GetSharedGroup(key string, skipCache bool) (sg *SharedGrou
defer ms.mu.RUnlock()
key = utils.SHARED_GROUP_PREFIX + key
if !skipCache {
- if x, err := cache2go.Get(key); err == nil {
+ if x, err := CacheGet(key); err == nil {
return x.(*SharedGroup), nil
} else {
return nil, err
@@ -494,7 +493,7 @@ func (ms *MapStorage) GetSharedGroup(key string, skipCache bool) (sg *SharedGrou
if values, ok := ms.dict[key]; ok {
err = ms.ms.Unmarshal(values, &sg)
if err == nil {
- cache2go.Cache(key, sg)
+ CacheSet(key, sg)
}
} else {
return nil, utils.ErrNotFound
@@ -657,7 +656,7 @@ func (ms *MapStorage) GetAlias(key string, skipCache bool) (al *Alias, err error
defer ms.mu.RUnlock()
key = utils.ALIASES_PREFIX + key
if !skipCache {
- if x, err := cache2go.Get(key); err == nil {
+ if x, err := CacheGet(key); err == nil {
al = &Alias{Values: x.(AliasValues)}
al.SetId(key[len(utils.ALIASES_PREFIX):])
return al, nil
@@ -670,7 +669,7 @@ func (ms *MapStorage) GetAlias(key string, skipCache bool) (al *Alias, err error
al.SetId(key[len(utils.ALIASES_PREFIX):])
err = ms.ms.Unmarshal(values, &al.Values)
if err == nil {
- cache2go.Cache(key, al.Values)
+ CacheSet(key, al.Values)
al.SetReverseCache()
}
} else {
@@ -692,7 +691,7 @@ func (ms *MapStorage) RemoveAlias(key string) error {
al.Values = aliasValues
delete(ms.dict, key)
al.RemoveReverseCache()
- cache2go.RemKey(key)
+ CacheRemKey(key)
return nil
}
@@ -737,7 +736,7 @@ func (ms *MapStorage) GetActionPlan(key string, skipCache bool) (ats *ActionPlan
defer ms.mu.RUnlock()
key = utils.ACTION_PLAN_PREFIX + key
if !skipCache {
- if x, err := cache2go.Get(key); err == nil {
+ if x, err := CacheGet(key); err == nil {
return x.(*ActionPlan), nil
} else {
return nil, err
@@ -745,7 +744,7 @@ func (ms *MapStorage) GetActionPlan(key string, skipCache bool) (ats *ActionPlan
}
if values, ok := ms.dict[key]; ok {
err = ms.ms.Unmarshal(values, &ats)
- cache2go.Cache(key, ats)
+ CacheSet(key, ats)
} else {
return nil, utils.ErrNotFound
}
@@ -758,7 +757,7 @@ func (ms *MapStorage) SetActionPlan(key string, ats *ActionPlan, overwrite bool)
defer ms.mu.Unlock()
// delete the key
delete(ms.dict, utils.ACTION_PLAN_PREFIX+key)
- cache2go.RemKey(utils.ACTION_PLAN_PREFIX + key)
+ CacheRemKey(utils.ACTION_PLAN_PREFIX + key)
return
}
if !overwrite {
@@ -782,7 +781,7 @@ func (ms *MapStorage) SetActionPlan(key string, ats *ActionPlan, overwrite bool)
func (ms *MapStorage) GetAllActionPlans() (ats map[string]*ActionPlan, err error) {
ms.mu.RLock()
defer ms.mu.RUnlock()
- apls, err := cache2go.GetAllEntries(utils.ACTION_PLAN_PREFIX)
+ apls, err := CacheGetAllEntries(utils.ACTION_PLAN_PREFIX)
if err != nil {
return nil, err
}
@@ -826,7 +825,7 @@ func (ms *MapStorage) GetDerivedChargers(key string, skipCache bool) (dcs *utils
defer ms.mu.RUnlock()
key = utils.DERIVEDCHARGERS_PREFIX + key
if !skipCache {
- if x, err := cache2go.Get(key); err == nil {
+ if x, err := CacheGet(key); err == nil {
return x.(*utils.DerivedChargers), nil
} else {
return nil, err
@@ -834,7 +833,7 @@ func (ms *MapStorage) GetDerivedChargers(key string, skipCache bool) (dcs *utils
}
if values, ok := ms.dict[key]; ok {
err = ms.ms.Unmarshal(values, &dcs)
- cache2go.Cache(key, dcs)
+ CacheSet(key, dcs)
} else {
return nil, utils.ErrNotFound
}
@@ -846,7 +845,7 @@ 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)
- cache2go.RemKey(utils.DERIVEDCHARGERS_PREFIX + key)
+ CacheRemKey(utils.DERIVEDCHARGERS_PREFIX + key)
return nil
}
result, err := ms.ms.Marshal(dcs)
diff --git a/engine/storage_mongo_datadb.go b/engine/storage_mongo_datadb.go
index 7437e307b..eab8e3eb0 100644
--- a/engine/storage_mongo_datadb.go
+++ b/engine/storage_mongo_datadb.go
@@ -26,7 +26,6 @@ import (
"io/ioutil"
"strings"
- "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
@@ -354,7 +353,7 @@ func (ms *MongoStorage) GetKeysForPrefix(prefix string, skipCache bool) ([]strin
}
return result, fmt.Errorf("unsupported prefix in GetKeysForPrefix: %s", prefix)
}
- return cache2go.GetEntriesKeys(prefix), nil
+ return CacheGetEntriesKeys(prefix), nil
}
func (ms *MongoStorage) Flush(ignore string) (err error) {
@@ -418,13 +417,13 @@ func (ms *MongoStorage) CacheRatingPrefixValues(prefixes map[string][]string) er
}
func (ms *MongoStorage) cacheRating(dKeys, rpKeys, rpfKeys, lcrKeys, dcsKeys, actKeys, aplKeys, shgKeys []string) (err error) {
- cache2go.BeginTransaction()
+ CacheBeginTransaction()
keyResult := struct{ Key string }{}
idResult := struct{ Id string }{}
session := ms.session.Copy()
defer session.Close()
db := session.DB(ms.db)
- if dKeys == nil || (float64(cache2go.CountEntries(utils.DESTINATION_PREFIX))*utils.DESTINATIONS_LOAD_THRESHOLD < float64(len(dKeys))) {
+ if dKeys == nil || (float64(CacheCountEntries(utils.DESTINATION_PREFIX))*utils.DESTINATIONS_LOAD_THRESHOLD < float64(len(dKeys))) {
// if need to load more than a half of exiting keys load them all
utils.Logger.Info("Caching all destinations")
iter := db.C(colDst).Find(nil).Select(bson.M{"key": 1}).Iter()
@@ -433,10 +432,10 @@ func (ms *MongoStorage) cacheRating(dKeys, rpKeys, rpfKeys, lcrKeys, dcsKeys, ac
dKeys = append(dKeys, utils.DESTINATION_PREFIX+keyResult.Key)
}
if err := iter.Close(); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("destinations: %s", err.Error())
}
- cache2go.RemPrefixKey(utils.DESTINATION_PREFIX)
+ CacheRemPrefixKey(utils.DESTINATION_PREFIX)
} else if len(dKeys) != 0 {
utils.Logger.Info(fmt.Sprintf("Caching destinations: %v", dKeys))
CleanStalePrefixes(dKeys)
@@ -447,7 +446,7 @@ func (ms *MongoStorage) cacheRating(dKeys, rpKeys, rpfKeys, lcrKeys, dcsKeys, ac
continue
}
if _, err = ms.GetDestination(key[len(utils.DESTINATION_PREFIX):]); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("destinations: %s", err.Error())
}
}
@@ -462,17 +461,17 @@ func (ms *MongoStorage) cacheRating(dKeys, rpKeys, rpfKeys, lcrKeys, dcsKeys, ac
rpKeys = append(rpKeys, utils.RATING_PLAN_PREFIX+keyResult.Key)
}
if err := iter.Close(); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("rating plans: %s", err.Error())
}
- cache2go.RemPrefixKey(utils.RATING_PLAN_PREFIX)
+ CacheRemPrefixKey(utils.RATING_PLAN_PREFIX)
} else if len(rpKeys) != 0 {
utils.Logger.Info(fmt.Sprintf("Caching rating plans: %v", rpKeys))
}
for _, key := range rpKeys {
- cache2go.RemKey(key)
+ CacheRemKey(key)
if _, err = ms.GetRatingPlan(key[len(utils.RATING_PLAN_PREFIX):], true); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("rating plans: %s", err.Error())
}
}
@@ -487,17 +486,17 @@ func (ms *MongoStorage) cacheRating(dKeys, rpKeys, rpfKeys, lcrKeys, dcsKeys, ac
rpfKeys = append(rpfKeys, utils.RATING_PROFILE_PREFIX+idResult.Id)
}
if err := iter.Close(); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("rating profiles: %s", err.Error())
}
- cache2go.RemPrefixKey(utils.RATING_PROFILE_PREFIX)
+ CacheRemPrefixKey(utils.RATING_PROFILE_PREFIX)
} else if len(rpfKeys) != 0 {
utils.Logger.Info(fmt.Sprintf("Caching rating profile: %v", rpfKeys))
}
for _, key := range rpfKeys {
- cache2go.RemKey(key)
+ CacheRemKey(key)
if _, err = ms.GetRatingProfile(key[len(utils.RATING_PROFILE_PREFIX):], true); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("rating profiles: %s", err.Error())
}
}
@@ -512,17 +511,17 @@ func (ms *MongoStorage) cacheRating(dKeys, rpKeys, rpfKeys, lcrKeys, dcsKeys, ac
lcrKeys = append(lcrKeys, utils.LCR_PREFIX+keyResult.Key)
}
if err := iter.Close(); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("lcr rules: %s", err.Error())
}
- cache2go.RemPrefixKey(utils.LCR_PREFIX)
+ CacheRemPrefixKey(utils.LCR_PREFIX)
} else if len(lcrKeys) != 0 {
utils.Logger.Info(fmt.Sprintf("Caching LCR rules: %v", lcrKeys))
}
for _, key := range lcrKeys {
- cache2go.RemKey(key)
+ CacheRemKey(key)
if _, err = ms.GetLCR(key[len(utils.LCR_PREFIX):], true); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("lcr rules: %s", err.Error())
}
}
@@ -538,17 +537,17 @@ func (ms *MongoStorage) cacheRating(dKeys, rpKeys, rpfKeys, lcrKeys, dcsKeys, ac
dcsKeys = append(dcsKeys, utils.DERIVEDCHARGERS_PREFIX+keyResult.Key)
}
if err := iter.Close(); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("derived chargers: %s", err.Error())
}
- cache2go.RemPrefixKey(utils.DERIVEDCHARGERS_PREFIX)
+ CacheRemPrefixKey(utils.DERIVEDCHARGERS_PREFIX)
} else if len(dcsKeys) != 0 {
utils.Logger.Info(fmt.Sprintf("Caching derived chargers: %v", dcsKeys))
}
for _, key := range dcsKeys {
- cache2go.RemKey(key)
+ CacheRemKey(key)
if _, err = ms.GetDerivedChargers(key[len(utils.DERIVEDCHARGERS_PREFIX):], true); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("derived chargers: %s", err.Error())
}
}
@@ -556,7 +555,7 @@ func (ms *MongoStorage) cacheRating(dKeys, rpKeys, rpfKeys, lcrKeys, dcsKeys, ac
utils.Logger.Info("Finished derived chargers caching.")
}
if actKeys == nil {
- cache2go.RemPrefixKey(utils.ACTION_PREFIX)
+ CacheRemPrefixKey(utils.ACTION_PREFIX)
}
if actKeys == nil {
utils.Logger.Info("Caching all actions")
@@ -566,17 +565,17 @@ func (ms *MongoStorage) cacheRating(dKeys, rpKeys, rpfKeys, lcrKeys, dcsKeys, ac
actKeys = append(actKeys, utils.ACTION_PREFIX+keyResult.Key)
}
if err := iter.Close(); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("actions: %s", err.Error())
}
- cache2go.RemPrefixKey(utils.ACTION_PREFIX)
+ CacheRemPrefixKey(utils.ACTION_PREFIX)
} else if len(actKeys) != 0 {
utils.Logger.Info(fmt.Sprintf("Caching actions: %v", actKeys))
}
for _, key := range actKeys {
- cache2go.RemKey(key)
+ CacheRemKey(key)
if _, err = ms.GetActions(key[len(utils.ACTION_PREFIX):], true); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("actions: %s", err.Error())
}
}
@@ -585,7 +584,7 @@ func (ms *MongoStorage) cacheRating(dKeys, rpKeys, rpfKeys, lcrKeys, dcsKeys, ac
}
if aplKeys == nil {
- cache2go.RemPrefixKey(utils.ACTION_PLAN_PREFIX)
+ CacheRemPrefixKey(utils.ACTION_PLAN_PREFIX)
}
if aplKeys == nil {
utils.Logger.Info("Caching all action plans")
@@ -595,17 +594,17 @@ func (ms *MongoStorage) cacheRating(dKeys, rpKeys, rpfKeys, lcrKeys, dcsKeys, ac
aplKeys = append(aplKeys, utils.ACTION_PLAN_PREFIX+keyResult.Key)
}
if err := iter.Close(); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("action plans: %s", err.Error())
}
- cache2go.RemPrefixKey(utils.ACTION_PLAN_PREFIX)
+ CacheRemPrefixKey(utils.ACTION_PLAN_PREFIX)
} else if len(aplKeys) != 0 {
utils.Logger.Info(fmt.Sprintf("Caching action plans: %v", aplKeys))
}
for _, key := range aplKeys {
- cache2go.RemKey(key)
+ CacheRemKey(key)
if _, err = ms.GetActionPlan(key[len(utils.ACTION_PLAN_PREFIX):], true); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("action plans: %s", err.Error())
}
}
@@ -614,7 +613,7 @@ func (ms *MongoStorage) cacheRating(dKeys, rpKeys, rpfKeys, lcrKeys, dcsKeys, ac
}
if shgKeys == nil {
- cache2go.RemPrefixKey(utils.SHARED_GROUP_PREFIX)
+ CacheRemPrefixKey(utils.SHARED_GROUP_PREFIX)
}
if shgKeys == nil {
utils.Logger.Info("Caching all shared groups")
@@ -624,23 +623,23 @@ func (ms *MongoStorage) cacheRating(dKeys, rpKeys, rpfKeys, lcrKeys, dcsKeys, ac
shgKeys = append(shgKeys, utils.SHARED_GROUP_PREFIX+idResult.Id)
}
if err := iter.Close(); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("shared groups: %s", err.Error())
}
} else if len(shgKeys) != 0 {
utils.Logger.Info(fmt.Sprintf("Caching shared groups: %v", shgKeys))
}
for _, key := range shgKeys {
- cache2go.RemKey(key)
+ CacheRemKey(key)
if _, err = ms.GetSharedGroup(key[len(utils.SHARED_GROUP_PREFIX):], true); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("shared groups: %s", err.Error())
}
}
if len(shgKeys) != 0 {
utils.Logger.Info("Finished shared groups caching.")
}
- cache2go.CommitTransaction()
+ CacheCommitTransaction()
return nil
}
@@ -675,10 +674,10 @@ func (ms *MongoStorage) CacheAccountingPrefixValues(prefixes map[string][]string
}
func (ms *MongoStorage) cacheAccounting(alsKeys []string) (err error) {
- cache2go.BeginTransaction()
+ CacheBeginTransaction()
var keyResult struct{ Key string }
if alsKeys == nil {
- cache2go.RemPrefixKey(utils.ALIASES_PREFIX)
+ CacheRemPrefixKey(utils.ALIASES_PREFIX)
}
session := ms.session.Copy()
defer session.Close()
@@ -691,7 +690,7 @@ func (ms *MongoStorage) cacheAccounting(alsKeys []string) (err error) {
alsKeys = append(alsKeys, utils.ALIASES_PREFIX+keyResult.Key)
}
if err := iter.Close(); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("aliases: %s", err.Error())
}
} else if len(alsKeys) != 0 {
@@ -700,14 +699,14 @@ func (ms *MongoStorage) cacheAccounting(alsKeys []string) (err error) {
for _, key := range alsKeys {
// check if it already exists
// to remove reverse cache keys
- if avs, err := cache2go.Get(key); err == nil && avs != nil {
+ if avs, err := CacheGet(key); err == nil && avs != nil {
al := &Alias{Values: avs.(AliasValues)}
al.SetId(key[len(utils.ALIASES_PREFIX):])
al.RemoveReverseCache()
}
- cache2go.RemKey(key)
+ CacheRemKey(key)
if _, err = ms.GetAlias(key[len(utils.ALIASES_PREFIX):], true); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("aliases: %s", err.Error())
}
}
@@ -716,11 +715,11 @@ func (ms *MongoStorage) cacheAccounting(alsKeys []string) (err error) {
}
utils.Logger.Info("Caching load history")
if _, err = ms.GetLoadHistory(1, true); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return err
}
utils.Logger.Info("Finished load history caching.")
- cache2go.CommitTransaction()
+ CacheCommitTransaction()
return nil
}
@@ -753,7 +752,7 @@ func (ms *MongoStorage) HasData(category, subject string) (bool, error) {
func (ms *MongoStorage) GetRatingPlan(key string, skipCache bool) (rp *RatingPlan, err error) {
if !skipCache {
- if x, err := cache2go.Get(utils.RATING_PLAN_PREFIX + key); err == nil {
+ if x, err := CacheGet(utils.RATING_PLAN_PREFIX + key); err == nil {
return x.(*RatingPlan), nil
} else {
return nil, err
@@ -782,7 +781,7 @@ func (ms *MongoStorage) GetRatingPlan(key string, skipCache bool) (rp *RatingPla
if err != nil {
return nil, err
}
- cache2go.Cache(utils.RATING_PLAN_PREFIX+key, rp)
+ CacheSet(utils.RATING_PLAN_PREFIX+key, rp)
}
return
}
@@ -811,7 +810,7 @@ func (ms *MongoStorage) SetRatingPlan(rp *RatingPlan) error {
func (ms *MongoStorage) GetRatingProfile(key string, skipCache bool) (rp *RatingProfile, err error) {
if !skipCache {
- if x, err := cache2go.Get(utils.RATING_PROFILE_PREFIX + key); err == nil {
+ if x, err := CacheGet(utils.RATING_PROFILE_PREFIX + key); err == nil {
return x.(*RatingProfile), nil
} else {
return nil, err
@@ -822,7 +821,7 @@ func (ms *MongoStorage) GetRatingProfile(key string, skipCache bool) (rp *Rating
defer session.Close()
err = col.Find(bson.M{"id": key}).One(rp)
if err == nil {
- cache2go.Cache(utils.RATING_PROFILE_PREFIX+key, rp)
+ CacheSet(utils.RATING_PROFILE_PREFIX+key, rp)
}
return
}
@@ -847,7 +846,7 @@ func (ms *MongoStorage) RemoveRatingProfile(key string) error {
if err := col.Remove(bson.M{"id": result.Id}); err != nil {
return err
}
- cache2go.RemKey(utils.RATING_PROFILE_PREFIX + key)
+ CacheRemKey(utils.RATING_PROFILE_PREFIX + key)
rpf := &RatingProfile{Id: result.Id}
if historyScribe != nil {
var response int
@@ -859,7 +858,7 @@ func (ms *MongoStorage) RemoveRatingProfile(key string) error {
func (ms *MongoStorage) GetLCR(key string, skipCache bool) (lcr *LCR, err error) {
if !skipCache {
- if x, err := cache2go.Get(utils.LCR_PREFIX + key); err == nil {
+ if x, err := CacheGet(utils.LCR_PREFIX + key); err == nil {
return x.(*LCR), nil
} else {
return nil, err
@@ -874,7 +873,7 @@ func (ms *MongoStorage) GetLCR(key string, skipCache bool) (lcr *LCR, err error)
err = col.Find(bson.M{"key": key}).One(&result)
if err == nil {
lcr = result.Value
- cache2go.Cache(utils.LCR_PREFIX+key, lcr)
+ CacheSet(utils.LCR_PREFIX+key, lcr)
}
return
}
@@ -915,7 +914,7 @@ func (ms *MongoStorage) GetDestination(key string) (result *Destination, err err
}
// create optimized structure
for _, p := range result.Prefixes {
- cache2go.Push(utils.DESTINATION_PREFIX+p, result.Id)
+ CachePush(utils.DESTINATION_PREFIX+p, result.Id)
}
}
if err != nil {
@@ -952,7 +951,7 @@ func (ms *MongoStorage) RemoveDestination(destID string) (err error) {
func (ms *MongoStorage) GetActions(key string, skipCache bool) (as Actions, err error) {
if !skipCache {
- if x, err := cache2go.Get(utils.ACTION_PREFIX + key); err == nil {
+ if x, err := CacheGet(utils.ACTION_PREFIX + key); err == nil {
return x.(Actions), nil
} else {
return nil, err
@@ -967,7 +966,7 @@ func (ms *MongoStorage) GetActions(key string, skipCache bool) (as Actions, err
err = col.Find(bson.M{"key": key}).One(&result)
if err == nil {
as = result.Value
- cache2go.Cache(utils.ACTION_PREFIX+key, as)
+ CacheSet(utils.ACTION_PREFIX+key, as)
}
return
}
@@ -990,7 +989,7 @@ func (ms *MongoStorage) RemoveActions(key string) error {
func (ms *MongoStorage) GetSharedGroup(key string, skipCache bool) (sg *SharedGroup, err error) {
if !skipCache {
- if x, err := cache2go.Get(utils.SHARED_GROUP_PREFIX + key); err == nil {
+ if x, err := CacheGet(utils.SHARED_GROUP_PREFIX + key); err == nil {
return x.(*SharedGroup), nil
} else {
return nil, err
@@ -1001,7 +1000,7 @@ func (ms *MongoStorage) GetSharedGroup(key string, skipCache bool) (sg *SharedGr
sg = &SharedGroup{}
err = col.Find(bson.M{"id": key}).One(sg)
if err == nil {
- cache2go.Cache(utils.SHARED_GROUP_PREFIX+key, sg)
+ CacheSet(utils.SHARED_GROUP_PREFIX+key, sg)
}
return
}
@@ -1165,7 +1164,7 @@ func (ms *MongoStorage) GetAlias(key string, skipCache bool) (al *Alias, err err
origKey := key
key = utils.ALIASES_PREFIX + key
if !skipCache {
- if x, err := cache2go.Get(key); err == nil {
+ if x, err := CacheGet(key); err == nil {
al = &Alias{Values: x.(AliasValues)}
al.SetId(origKey)
return al, nil
@@ -1183,7 +1182,7 @@ func (ms *MongoStorage) GetAlias(key string, skipCache bool) (al *Alias, err err
al = &Alias{Values: kv.Value}
al.SetId(origKey)
if err == nil {
- cache2go.Cache(key, al.Values)
+ CacheSet(key, al.Values)
// cache reverse alias
al.SetReverseCache()
}
@@ -1208,7 +1207,7 @@ func (ms *MongoStorage) RemoveAlias(key string) (err error) {
err = col.Remove(bson.M{"key": origKey})
if err == nil {
al.RemoveReverseCache()
- cache2go.RemKey(key)
+ CacheRemKey(key)
}
return
}
@@ -1219,7 +1218,7 @@ func (ms *MongoStorage) GetLoadHistory(limit int, skipCache bool) (loadInsts []*
return nil, nil
}
if !skipCache {
- if x, err := cache2go.Get(utils.LOADINST_KEY); err != nil {
+ if x, err := CacheGet(utils.LOADINST_KEY); err != nil {
return nil, err
} else {
items := x.([]*utils.LoadInstance)
@@ -1238,8 +1237,8 @@ func (ms *MongoStorage) GetLoadHistory(limit int, skipCache bool) (loadInsts []*
err = col.Find(bson.M{"key": utils.LOADINST_KEY}).One(&kv)
if err == nil {
loadInsts = kv.Value
- cache2go.RemKey(utils.LOADINST_KEY)
- cache2go.Cache(utils.LOADINST_KEY, loadInsts)
+ CacheRemKey(utils.LOADINST_KEY)
+ CacheSet(utils.LOADINST_KEY, loadInsts)
}
return loadInsts, nil
}
@@ -1322,7 +1321,7 @@ func (ms *MongoStorage) SetActionTriggers(key string, atrs ActionTriggers) (err
func (ms *MongoStorage) GetActionPlan(key string, skipCache bool) (ats *ActionPlan, err error) {
if !skipCache {
- if x, err := cache2go.Get(utils.ACTION_PLAN_PREFIX + key); err == nil {
+ if x, err := CacheGet(utils.ACTION_PLAN_PREFIX + key); err == nil {
return x.(*ActionPlan), nil
} else {
return nil, err
@@ -1350,7 +1349,7 @@ func (ms *MongoStorage) GetActionPlan(key string, skipCache bool) (ats *ActionPl
if err != nil {
return nil, err
}
- cache2go.Cache(utils.ACTION_PLAN_PREFIX+key, ats)
+ CacheSet(utils.ACTION_PLAN_PREFIX+key, ats)
}
return
}
@@ -1360,7 +1359,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 {
- cache2go.RemKey(utils.ACTION_PLAN_PREFIX + key)
+ CacheRemKey(utils.ACTION_PLAN_PREFIX + key)
err := col.Remove(bson.M{"key": key})
if err != mgo.ErrNotFound {
return err
@@ -1394,7 +1393,7 @@ func (ms *MongoStorage) SetActionPlan(key string, ats *ActionPlan, overwrite boo
}
func (ms *MongoStorage) GetAllActionPlans() (ats map[string]*ActionPlan, err error) {
- apls, err := cache2go.GetAllEntries(utils.ACTION_PLAN_PREFIX)
+ apls, err := CacheGetAllEntries(utils.ACTION_PLAN_PREFIX)
if err != nil {
return nil, err
}
@@ -1433,7 +1432,7 @@ func (ms *MongoStorage) PopTask() (t *Task, err error) {
func (ms *MongoStorage) GetDerivedChargers(key string, skipCache bool) (dcs *utils.DerivedChargers, err error) {
if !skipCache {
- if x, err := cache2go.Get(utils.DERIVEDCHARGERS_PREFIX + key); err == nil {
+ if x, err := CacheGet(utils.DERIVEDCHARGERS_PREFIX + key); err == nil {
return x.(*utils.DerivedChargers), nil
} else {
return nil, err
@@ -1448,14 +1447,14 @@ func (ms *MongoStorage) GetDerivedChargers(key string, skipCache bool) (dcs *uti
err = col.Find(bson.M{"key": key}).One(&kv)
if err == nil {
dcs = kv.Value
- cache2go.Cache(utils.DERIVEDCHARGERS_PREFIX+key, dcs)
+ CacheSet(utils.DERIVEDCHARGERS_PREFIX+key, dcs)
}
return
}
func (ms *MongoStorage) SetDerivedChargers(key string, dcs *utils.DerivedChargers) (err error) {
if dcs == nil || len(dcs.Chargers) == 0 {
- cache2go.RemKey(utils.DERIVEDCHARGERS_PREFIX + key)
+ CacheRemKey(utils.DERIVEDCHARGERS_PREFIX + key)
session, col := ms.conn(colDcs)
defer session.Close()
err = col.Remove(bson.M{"key": key})
diff --git a/engine/storage_redis.go b/engine/storage_redis.go
index e82db4c01..c735ced8d 100644
--- a/engine/storage_redis.go
+++ b/engine/storage_redis.go
@@ -26,7 +26,6 @@ import (
"io/ioutil"
"time"
- "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
"github.com/mediocregopher/radix.v2/pool"
"github.com/mediocregopher/radix.v2/redis"
@@ -92,7 +91,7 @@ func (rs *RedisStorage) GetKeysForPrefix(prefix string, skipCache bool) ([]strin
}
return r.List()
}
- return cache2go.GetEntriesKeys(prefix), nil
+ return CacheGetEntriesKeys(prefix), nil
}
func (rs *RedisStorage) CacheRatingAll() error {
@@ -140,20 +139,20 @@ func (rs *RedisStorage) CacheRatingPrefixValues(prefixes map[string][]string) er
}
func (rs *RedisStorage) cacheRating(dKeys, rpKeys, rpfKeys, lcrKeys, dcsKeys, actKeys, aplKeys, shgKeys []string) (err error) {
- cache2go.BeginTransaction()
+ CacheBeginTransaction()
conn, err := rs.db.Get()
if err != nil {
return err
}
defer rs.db.Put(conn)
- if dKeys == nil || (float64(cache2go.CountEntries(utils.DESTINATION_PREFIX))*utils.DESTINATIONS_LOAD_THRESHOLD < float64(len(dKeys))) {
+ if dKeys == nil || (float64(CacheCountEntries(utils.DESTINATION_PREFIX))*utils.DESTINATIONS_LOAD_THRESHOLD < float64(len(dKeys))) {
// if need to load more than a half of exiting keys load them all
utils.Logger.Info("Caching all destinations")
if dKeys, err = conn.Cmd("KEYS", utils.DESTINATION_PREFIX+"*").List(); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("destinations: %s", err.Error())
}
- cache2go.RemPrefixKey(utils.DESTINATION_PREFIX)
+ CacheRemPrefixKey(utils.DESTINATION_PREFIX)
} else if len(dKeys) != 0 {
utils.Logger.Info(fmt.Sprintf("Caching destinations: %v", dKeys))
CleanStalePrefixes(dKeys)
@@ -164,7 +163,7 @@ func (rs *RedisStorage) cacheRating(dKeys, rpKeys, rpfKeys, lcrKeys, dcsKeys, ac
continue
}
if _, err = rs.GetDestination(key[len(utils.DESTINATION_PREFIX):]); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("destinations: %s", err.Error())
}
}
@@ -174,17 +173,17 @@ func (rs *RedisStorage) cacheRating(dKeys, rpKeys, rpfKeys, lcrKeys, dcsKeys, ac
if rpKeys == nil {
utils.Logger.Info("Caching all rating plans")
if rpKeys, err = conn.Cmd("KEYS", utils.RATING_PLAN_PREFIX+"*").List(); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("rating plans: %s", err.Error())
}
- cache2go.RemPrefixKey(utils.RATING_PLAN_PREFIX)
+ CacheRemPrefixKey(utils.RATING_PLAN_PREFIX)
} else if len(rpKeys) != 0 {
utils.Logger.Info(fmt.Sprintf("Caching rating plans: %v", rpKeys))
}
for _, key := range rpKeys {
- cache2go.RemKey(key)
+ CacheRemKey(key)
if _, err = rs.GetRatingPlan(key[len(utils.RATING_PLAN_PREFIX):], true); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("rating plans: %s", err.Error())
}
}
@@ -194,17 +193,17 @@ func (rs *RedisStorage) cacheRating(dKeys, rpKeys, rpfKeys, lcrKeys, dcsKeys, ac
if rpfKeys == nil {
utils.Logger.Info("Caching all rating profiles")
if rpfKeys, err = conn.Cmd("KEYS", utils.RATING_PROFILE_PREFIX+"*").List(); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("rating profiles: %s", err.Error())
}
- cache2go.RemPrefixKey(utils.RATING_PROFILE_PREFIX)
+ CacheRemPrefixKey(utils.RATING_PROFILE_PREFIX)
} else if len(rpfKeys) != 0 {
utils.Logger.Info(fmt.Sprintf("Caching rating profile: %v", rpfKeys))
}
for _, key := range rpfKeys {
- cache2go.RemKey(key)
+ CacheRemKey(key)
if _, err = rs.GetRatingProfile(key[len(utils.RATING_PROFILE_PREFIX):], true); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("rating profiles: %s", err.Error())
}
}
@@ -214,17 +213,17 @@ func (rs *RedisStorage) cacheRating(dKeys, rpKeys, rpfKeys, lcrKeys, dcsKeys, ac
if lcrKeys == nil {
utils.Logger.Info("Caching LCR rules.")
if lcrKeys, err = conn.Cmd("KEYS", utils.LCR_PREFIX+"*").List(); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("lcr rules: %s", err.Error())
}
- cache2go.RemPrefixKey(utils.LCR_PREFIX)
+ CacheRemPrefixKey(utils.LCR_PREFIX)
} else if len(lcrKeys) != 0 {
utils.Logger.Info(fmt.Sprintf("Caching LCR rules: %v", lcrKeys))
}
for _, key := range lcrKeys {
- cache2go.RemKey(key)
+ CacheRemKey(key)
if _, err = rs.GetLCR(key[len(utils.LCR_PREFIX):], true); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("lcr rules: %s", err.Error())
}
}
@@ -235,17 +234,17 @@ func (rs *RedisStorage) cacheRating(dKeys, rpKeys, rpfKeys, lcrKeys, dcsKeys, ac
if dcsKeys == nil {
utils.Logger.Info("Caching all derived chargers")
if dcsKeys, err = conn.Cmd("KEYS", utils.DERIVEDCHARGERS_PREFIX+"*").List(); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("derived chargers: %s", err.Error())
}
- cache2go.RemPrefixKey(utils.DERIVEDCHARGERS_PREFIX)
+ CacheRemPrefixKey(utils.DERIVEDCHARGERS_PREFIX)
} else if len(dcsKeys) != 0 {
utils.Logger.Info(fmt.Sprintf("Caching derived chargers: %v", dcsKeys))
}
for _, key := range dcsKeys {
- cache2go.RemKey(key)
+ CacheRemKey(key)
if _, err = rs.GetDerivedChargers(key[len(utils.DERIVEDCHARGERS_PREFIX):], true); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("derived chargers: %s", err.Error())
}
}
@@ -255,17 +254,17 @@ func (rs *RedisStorage) cacheRating(dKeys, rpKeys, rpfKeys, lcrKeys, dcsKeys, ac
if actKeys == nil {
utils.Logger.Info("Caching all actions")
if actKeys, err = conn.Cmd("KEYS", utils.ACTION_PREFIX+"*").List(); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("actions: %s", err.Error())
}
- cache2go.RemPrefixKey(utils.ACTION_PREFIX)
+ CacheRemPrefixKey(utils.ACTION_PREFIX)
} else if len(actKeys) != 0 {
utils.Logger.Info(fmt.Sprintf("Caching actions: %v", actKeys))
}
for _, key := range actKeys {
- cache2go.RemKey(key)
+ CacheRemKey(key)
if _, err = rs.GetActions(key[len(utils.ACTION_PREFIX):], true); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("actions: %s", err.Error())
}
}
@@ -276,17 +275,17 @@ func (rs *RedisStorage) cacheRating(dKeys, rpKeys, rpfKeys, lcrKeys, dcsKeys, ac
if aplKeys == nil {
utils.Logger.Info("Caching all action plans")
if aplKeys, err = rs.db.Cmd("KEYS", utils.ACTION_PLAN_PREFIX+"*").List(); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf(" %s", err.Error())
}
- cache2go.RemPrefixKey(utils.ACTION_PLAN_PREFIX)
+ CacheRemPrefixKey(utils.ACTION_PLAN_PREFIX)
} else if len(aplKeys) != 0 {
utils.Logger.Info(fmt.Sprintf("Caching action plan: %v", aplKeys))
}
for _, key := range aplKeys {
- cache2go.RemKey(key)
+ CacheRemKey(key)
if _, err = rs.GetActionPlan(key[len(utils.ACTION_PLAN_PREFIX):], true); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf(" %s", err.Error())
}
}
@@ -297,17 +296,17 @@ func (rs *RedisStorage) cacheRating(dKeys, rpKeys, rpfKeys, lcrKeys, dcsKeys, ac
if shgKeys == nil {
utils.Logger.Info("Caching all shared groups")
if shgKeys, err = conn.Cmd("KEYS", utils.SHARED_GROUP_PREFIX+"*").List(); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("shared groups: %s", err.Error())
}
- cache2go.RemPrefixKey(utils.SHARED_GROUP_PREFIX)
+ CacheRemPrefixKey(utils.SHARED_GROUP_PREFIX)
} else if len(shgKeys) != 0 {
utils.Logger.Info(fmt.Sprintf("Caching shared groups: %v", shgKeys))
}
for _, key := range shgKeys {
- cache2go.RemKey(key)
+ CacheRemKey(key)
if _, err = rs.GetSharedGroup(key[len(utils.SHARED_GROUP_PREFIX):], true); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("shared groups: %s", err.Error())
}
}
@@ -315,7 +314,7 @@ func (rs *RedisStorage) cacheRating(dKeys, rpKeys, rpfKeys, lcrKeys, dcsKeys, ac
utils.Logger.Info("Finished shared groups caching.")
}
- cache2go.CommitTransaction()
+ CacheCommitTransaction()
return nil
}
@@ -350,7 +349,7 @@ func (rs *RedisStorage) CacheAccountingPrefixValues(prefixes map[string][]string
}
func (rs *RedisStorage) cacheAccounting(alsKeys []string) (err error) {
- cache2go.BeginTransaction()
+ CacheBeginTransaction()
conn, err := rs.db.Get()
if err != nil {
return err
@@ -359,11 +358,11 @@ func (rs *RedisStorage) cacheAccounting(alsKeys []string) (err error) {
if alsKeys == nil {
utils.Logger.Info("Caching all aliases")
if alsKeys, err = conn.Cmd("KEYS", utils.ALIASES_PREFIX+"*").List(); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("aliases: %s", err.Error())
}
- cache2go.RemPrefixKey(utils.ALIASES_PREFIX)
- cache2go.RemPrefixKey(utils.REVERSE_ALIASES_PREFIX)
+ CacheRemPrefixKey(utils.ALIASES_PREFIX)
+ CacheRemPrefixKey(utils.REVERSE_ALIASES_PREFIX)
} else if len(alsKeys) != 0 {
utils.Logger.Info(fmt.Sprintf("Caching aliases: %v", alsKeys))
}
@@ -371,14 +370,14 @@ func (rs *RedisStorage) cacheAccounting(alsKeys []string) (err error) {
for _, key := range alsKeys {
// check if it already exists
// to remove reverse cache keys
- if avs, err := cache2go.Get(key); err == nil && avs != nil {
+ if avs, err := CacheGet(key); err == nil && avs != nil {
al.Values = avs.(AliasValues)
al.SetId(key[len(utils.ALIASES_PREFIX):])
al.RemoveReverseCache()
}
- cache2go.RemKey(key)
+ CacheRemKey(key)
if _, err = rs.GetAlias(key[len(utils.ALIASES_PREFIX):], true); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return fmt.Errorf("aliases: %s", err.Error())
}
}
@@ -387,11 +386,11 @@ func (rs *RedisStorage) cacheAccounting(alsKeys []string) (err error) {
}
utils.Logger.Info("Caching load history")
if _, err = rs.GetLoadHistory(1, true); err != nil {
- cache2go.RollbackTransaction()
+ CacheRollbackTransaction()
return err
}
utils.Logger.Info("Finished load history caching.")
- cache2go.CommitTransaction()
+ CacheCommitTransaction()
return nil
}
@@ -408,7 +407,7 @@ func (rs *RedisStorage) HasData(category, subject string) (bool, error) {
func (rs *RedisStorage) GetRatingPlan(key string, skipCache bool) (rp *RatingPlan, err error) {
key = utils.RATING_PLAN_PREFIX + key
if !skipCache {
- if x, err := cache2go.Get(key); err == nil {
+ if x, err := CacheGet(key); err == nil {
return x.(*RatingPlan), nil
} else {
return nil, err
@@ -428,7 +427,7 @@ func (rs *RedisStorage) GetRatingPlan(key string, skipCache bool) (rp *RatingPla
r.Close()
rp = new(RatingPlan)
err = rs.ms.Unmarshal(out, rp)
- cache2go.Cache(key, rp)
+ CacheSet(key, rp)
}
return
}
@@ -451,7 +450,7 @@ func (rs *RedisStorage) GetRatingProfile(key string, skipCache bool) (rpf *Ratin
key = utils.RATING_PROFILE_PREFIX + key
if !skipCache {
- if x, err := cache2go.Get(key); err == nil {
+ if x, err := CacheGet(key); err == nil {
return x.(*RatingProfile), nil
} else {
return nil, err
@@ -461,7 +460,7 @@ func (rs *RedisStorage) GetRatingProfile(key string, skipCache bool) (rpf *Ratin
if values, err = rs.db.Cmd("GET", key).Bytes(); err == nil {
rpf = new(RatingProfile)
err = rs.ms.Unmarshal(values, rpf)
- cache2go.Cache(key, rpf)
+ CacheSet(key, rpf)
}
return
}
@@ -490,7 +489,7 @@ func (rs *RedisStorage) RemoveRatingProfile(key string) error {
if err = conn.Cmd("DEL", key).Err; err != nil {
return err
}
- cache2go.RemKey(key)
+ CacheRemKey(key)
rpf := &RatingProfile{Id: key}
if historyScribe != nil {
response := 0
@@ -503,7 +502,7 @@ func (rs *RedisStorage) RemoveRatingProfile(key string) error {
func (rs *RedisStorage) GetLCR(key string, skipCache bool) (lcr *LCR, err error) {
key = utils.LCR_PREFIX + key
if !skipCache {
- if x, err := cache2go.Get(key); err == nil {
+ if x, err := CacheGet(key); err == nil {
return x.(*LCR), nil
} else {
return nil, err
@@ -512,7 +511,7 @@ func (rs *RedisStorage) GetLCR(key string, skipCache bool) (lcr *LCR, err error)
var values []byte
if values, err = rs.db.Cmd("GET", key).Bytes(); err == nil {
err = rs.ms.Unmarshal(values, &lcr)
- cache2go.Cache(key, lcr)
+ CacheSet(key, lcr)
}
return
}
@@ -520,7 +519,7 @@ func (rs *RedisStorage) GetLCR(key string, skipCache bool) (lcr *LCR, err error)
func (rs *RedisStorage) SetLCR(lcr *LCR) (err error) {
result, err := rs.ms.Marshal(lcr)
err = rs.db.Cmd("SET", utils.LCR_PREFIX+lcr.GetId(), result).Err
- cache2go.Cache(utils.LCR_PREFIX+lcr.GetId(), lcr)
+ CacheSet(utils.LCR_PREFIX+lcr.GetId(), lcr)
return
}
@@ -542,7 +541,7 @@ func (rs *RedisStorage) GetDestination(key string) (dest *Destination, err error
err = rs.ms.Unmarshal(out, dest)
// create optimized structure
for _, p := range dest.Prefixes {
- cache2go.Push(utils.DESTINATION_PREFIX+p, dest.Id)
+ CachePush(utils.DESTINATION_PREFIX+p, dest.Id)
}
} else {
return nil, utils.ErrNotFound
@@ -597,11 +596,11 @@ func (rs *RedisStorage) RemoveDestination(destID string) (err error) {
if dest != nil {
for _, prefix := range dest.Prefixes {
changed := false
- if idIDs, err := cache2go.Get(utils.DESTINATION_PREFIX + prefix); err == nil {
+ if idIDs, err := CacheGet(utils.DESTINATION_PREFIX + prefix); err == nil {
dIDs := idIDs.(map[interface{}]struct{})
if len(dIDs) == 1 {
// remove de prefix from cache
- cache2go.RemKey(utils.DESTINATION_PREFIX + prefix)
+ CacheRemKey(utils.DESTINATION_PREFIX + prefix)
} else {
// delete the destination from list and put the new list in chache
delete(dIDs, searchedDID)
@@ -609,7 +608,7 @@ func (rs *RedisStorage) RemoveDestination(destID string) (err error) {
}
}
if changed {
- cache2go.Cache(utils.DESTINATION_PREFIX+prefix, dIDs)
+ CacheSet(utils.DESTINATION_PREFIX+prefix, dIDs)
}
}
}
@@ -625,7 +624,7 @@ func (rs *RedisStorage) RemoveDestination(destID string) (err error) {
func (rs *RedisStorage) GetActions(key string, skipCache bool) (as Actions, err error) {
key = utils.ACTION_PREFIX + key
if !skipCache {
- if x, err := cache2go.Get(key); err == nil {
+ if x, err := CacheGet(key); err == nil {
return x.(Actions), nil
} else {
return nil, err
@@ -634,7 +633,7 @@ func (rs *RedisStorage) GetActions(key string, skipCache bool) (as Actions, err
var values []byte
if values, err = rs.db.Cmd("GET", key).Bytes(); err == nil {
err = rs.ms.Unmarshal(values, &as)
- cache2go.Cache(key, as)
+ CacheSet(key, as)
}
return
}
@@ -653,7 +652,7 @@ func (rs *RedisStorage) RemoveActions(key string) (err error) {
func (rs *RedisStorage) GetSharedGroup(key string, skipCache bool) (sg *SharedGroup, err error) {
key = utils.SHARED_GROUP_PREFIX + key
if !skipCache {
- if x, err := cache2go.Get(key); err == nil {
+ if x, err := CacheGet(key); err == nil {
return x.(*SharedGroup), nil
} else {
return nil, err
@@ -662,7 +661,7 @@ func (rs *RedisStorage) GetSharedGroup(key string, skipCache bool) (sg *SharedGr
var values []byte
if values, err = rs.db.Cmd("GET", key).Bytes(); err == nil {
err = rs.ms.Unmarshal(values, &sg)
- cache2go.Cache(key, sg)
+ CacheSet(key, sg)
}
return
}
@@ -820,7 +819,7 @@ func (rs *RedisStorage) GetAlias(key string, skipCache bool) (al *Alias, err err
origKey := key
key = utils.ALIASES_PREFIX + key
if !skipCache {
- if x, err := cache2go.Get(key); err == nil {
+ if x, err := CacheGet(key); err == nil {
al = &Alias{Values: x.(AliasValues)}
al.SetId(origKey)
return al, nil
@@ -834,7 +833,7 @@ func (rs *RedisStorage) GetAlias(key string, skipCache bool) (al *Alias, err err
al.SetId(origKey)
err = rs.ms.Unmarshal(values, &al.Values)
if err == nil {
- cache2go.Cache(key, al.Values)
+ CacheSet(key, al.Values)
// cache reverse alias
al.SetReverseCache()
}
@@ -859,7 +858,7 @@ func (rs *RedisStorage) RemoveAlias(key string) (err error) {
err = conn.Cmd("DEL", key).Err
if err == nil {
al.RemoveReverseCache()
- cache2go.RemKey(key)
+ CacheRemKey(key)
}
return
}
@@ -870,7 +869,7 @@ func (rs *RedisStorage) GetLoadHistory(limit int, skipCache bool) ([]*utils.Load
return nil, nil
}
if !skipCache {
- if x, err := cache2go.Get(utils.LOADINST_KEY); err != nil {
+ if x, err := CacheGet(utils.LOADINST_KEY); err != nil {
return nil, err
} else {
items := x.([]*utils.LoadInstance)
@@ -896,8 +895,8 @@ func (rs *RedisStorage) GetLoadHistory(limit int, skipCache bool) ([]*utils.Load
}
loadInsts[idx] = &lInst
}
- cache2go.RemKey(utils.LOADINST_KEY)
- cache2go.Cache(utils.LOADINST_KEY, loadInsts)
+ CacheRemKey(utils.LOADINST_KEY)
+ CacheSet(utils.LOADINST_KEY, loadInsts)
return loadInsts, nil
}
@@ -959,7 +958,7 @@ func (rs *RedisStorage) SetActionTriggers(key string, atrs ActionTriggers) (err
func (rs *RedisStorage) GetActionPlan(key string, skipCache bool) (ats *ActionPlan, err error) {
key = utils.ACTION_PLAN_PREFIX + key
if !skipCache {
- if x, err := cache2go.Get(key); err == nil {
+ if x, err := CacheGet(key); err == nil {
return x.(*ActionPlan), nil
} else {
return nil, err
@@ -978,7 +977,7 @@ func (rs *RedisStorage) GetActionPlan(key string, skipCache bool) (ats *ActionPl
}
r.Close()
err = rs.ms.Unmarshal(out, &ats)
- cache2go.Cache(key, ats)
+ CacheSet(key, ats)
}
return
}
@@ -987,7 +986,7 @@ func (rs *RedisStorage) SetActionPlan(key string, ats *ActionPlan, overwrite boo
if len(ats.ActionTimings) == 0 {
// delete the key
err = rs.db.Cmd("DEL", utils.ACTION_PLAN_PREFIX+key).Err
- cache2go.RemKey(utils.ACTION_PLAN_PREFIX + key)
+ CacheRemKey(utils.ACTION_PLAN_PREFIX + key)
return err
}
if !overwrite {
@@ -1014,7 +1013,7 @@ func (rs *RedisStorage) SetActionPlan(key string, ats *ActionPlan, overwrite boo
}
func (rs *RedisStorage) GetAllActionPlans() (ats map[string]*ActionPlan, err error) {
- apls, err := cache2go.GetAllEntries(utils.ACTION_PLAN_PREFIX)
+ apls, err := CacheGetAllEntries(utils.ACTION_PLAN_PREFIX)
if err != nil {
return nil, err
}
@@ -1048,7 +1047,7 @@ func (rs *RedisStorage) PopTask() (t *Task, err error) {
func (rs *RedisStorage) GetDerivedChargers(key string, skipCache bool) (dcs *utils.DerivedChargers, err error) {
key = utils.DERIVEDCHARGERS_PREFIX + key
if !skipCache {
- if x, err := cache2go.Get(key); err == nil {
+ if x, err := CacheGet(key); err == nil {
return x.(*utils.DerivedChargers), nil
} else {
return nil, err
@@ -1057,7 +1056,7 @@ func (rs *RedisStorage) GetDerivedChargers(key string, skipCache bool) (dcs *uti
var values []byte
if values, err = rs.db.Cmd("GET", key).Bytes(); err == nil {
err = rs.ms.Unmarshal(values, &dcs)
- cache2go.Cache(key, dcs)
+ CacheSet(key, dcs)
}
return dcs, err
}
@@ -1065,7 +1064,7 @@ func (rs *RedisStorage) GetDerivedChargers(key string, skipCache bool) (dcs *uti
func (rs *RedisStorage) SetDerivedChargers(key string, dcs *utils.DerivedChargers) (err error) {
if dcs == nil || len(dcs.Chargers) == 0 {
err = rs.db.Cmd("DEL", utils.DERIVEDCHARGERS_PREFIX+key).Err
- cache2go.RemKey(utils.DERIVEDCHARGERS_PREFIX + key)
+ CacheRemKey(utils.DERIVEDCHARGERS_PREFIX + key)
return err
}
marshaled, err := rs.ms.Marshal(dcs)
diff --git a/engine/storage_test.go b/engine/storage_test.go
index 06c40e0d1..03e6818b0 100644
--- a/engine/storage_test.go
+++ b/engine/storage_test.go
@@ -22,7 +22,6 @@ import (
"testing"
"time"
- "github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
)
@@ -182,8 +181,8 @@ func TestStorageCacheGetReverseAliases(t *testing.T) {
Subject: "b1",
Context: "*other",
}
- if x, err := cache2go.Get(utils.REVERSE_ALIASES_PREFIX + "aaa" + "Subject" + utils.ALIAS_CONTEXT_RATING); err == nil {
- aliasKeys := x.(map[interface{}]struct{})
+ if x, err := CacheGet(utils.REVERSE_ALIASES_PREFIX + "aaa" + "Subject" + utils.ALIAS_CONTEXT_RATING); err == nil {
+ aliasKeys := x.(map[string]struct{})
_, found := aliasKeys[utils.ConcatenatedKey(ala.GetId(), utils.ANY)]
if !found {
t.Error("Error getting reverse alias: ", aliasKeys, ala.GetId()+utils.ANY)
@@ -191,8 +190,8 @@ func TestStorageCacheGetReverseAliases(t *testing.T) {
} else {
t.Error("Error getting reverse alias: ", err)
}
- if x, err := cache2go.Get(utils.REVERSE_ALIASES_PREFIX + "aaa" + "Account" + "*other"); err == nil {
- aliasKeys := x.(map[interface{}]struct{})
+ if x, err := CacheGet(utils.REVERSE_ALIASES_PREFIX + "aaa" + "Account" + "*other"); err == nil {
+ aliasKeys := x.(map[string]struct{})
_, found := aliasKeys[utils.ConcatenatedKey(alb.GetId(), utils.ANY)]
if !found {
t.Error("Error getting reverse alias: ", aliasKeys)
@@ -222,17 +221,17 @@ func TestStorageCacheRemoveCachedAliases(t *testing.T) {
accountingStorage.RemoveAlias(ala.GetId())
accountingStorage.RemoveAlias(alb.GetId())
- if _, err := cache2go.Get(utils.ALIASES_PREFIX + ala.GetId()); err == nil {
+ if _, err := CacheGet(utils.ALIASES_PREFIX + ala.GetId()); err == nil {
t.Error("Error removing cached alias: ", err)
}
- if _, err := cache2go.Get(utils.ALIASES_PREFIX + alb.GetId()); err == nil {
+ if _, err := CacheGet(utils.ALIASES_PREFIX + alb.GetId()); err == nil {
t.Error("Error removing cached alias: ", err)
}
- if _, err := cache2go.Get(utils.REVERSE_ALIASES_PREFIX + "aaa" + utils.ALIAS_CONTEXT_RATING); err == nil {
+ if _, err := CacheGet(utils.REVERSE_ALIASES_PREFIX + "aaa" + utils.ALIAS_CONTEXT_RATING); err == nil {
t.Error("Error removing cached reverse alias: ", err)
}
- if _, err := cache2go.Get(utils.REVERSE_ALIASES_PREFIX + "aaa" + utils.ALIAS_CONTEXT_RATING); err == nil {
+ if _, err := CacheGet(utils.REVERSE_ALIASES_PREFIX + "aaa" + utils.ALIAS_CONTEXT_RATING); err == nil {
t.Error("Error removing cached reverse alias: ", err)
}
}
diff --git a/sessionmanager/smg_session.go b/sessionmanager/smg_session.go
index 485cf2cdd..85302a6d8 100644
--- a/sessionmanager/smg_session.go
+++ b/sessionmanager/smg_session.go
@@ -195,7 +195,7 @@ func (self *SMGSession) refund(refundDuration time.Duration) error {
cd.CgrID = self.cd.CgrID
cd.RunID = self.cd.RunID
cd.Increments.Compress()
- utils.Logger.Info(fmt.Sprintf("Refunding %s duration %v with incerements: %s", cd.CgrID, initialRefundDuration, utils.ToJSON(cd.Increments)))
+ utils.Logger.Info(fmt.Sprintf("Refunding %s duration %v with cd: %s", cd.CgrID, initialRefundDuration, utils.ToJSON(cd)))
var response float64
err := self.rater.Call("Responder.RefundIncrements", cd, &response)
if err != nil {