From e657fb3ca8ed3f0be558c2557615c032399009c7 Mon Sep 17 00:00:00 2001 From: DanB Date: Tue, 22 Nov 2016 18:13:35 +0100 Subject: [PATCH] GetActionPlan from cache with GetCloned --- cache/cache.go | 2 ++ engine/storage_mongo_datadb.go | 9 ++++++--- engine/storage_redis.go | 9 ++++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cache/cache.go b/cache/cache.go index cecf47b87..dc7ceb38e 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -161,6 +161,8 @@ func GetCloned(key string) (cln interface{}, err error) { return nil, utils.NewCGRError(utils.Cache, utils.NotFoundCaps, utils.ItemNotFound, fmt.Sprintf("item with key <%s> was not found in <%s>", key)) + } else if origVal == nil { + return nil, nil } if _, canClone := origVal.(utils.Cloner); !canClone { return nil, utils.NewCGRError(utils.Cache, diff --git a/engine/storage_mongo_datadb.go b/engine/storage_mongo_datadb.go index bcfec945c..0b898de29 100644 --- a/engine/storage_mongo_datadb.go +++ b/engine/storage_mongo_datadb.go @@ -1374,11 +1374,14 @@ func (ms *MongoStorage) RemoveActionTriggers(key string, transactionID string) e func (ms *MongoStorage) GetActionPlan(key string, skipCache bool, transactionID string) (ats *ActionPlan, err error) { if !skipCache { - if x, ok := cache.Get(utils.ACTION_PLAN_PREFIX + key); ok { - if x != nil { - return x.(*ActionPlan), nil + if x, err := cache.GetCloned(key); err != nil { + if err.Error() != utils.ItemNotFound { // Only consider cache if item was found + return nil, err } + } else if x == nil { // item was placed nil in cache return nil, utils.ErrNotFound + } else { + return x.(*ActionPlan), nil } } var kv struct { diff --git a/engine/storage_redis.go b/engine/storage_redis.go index 3967db7d4..525b1497f 100644 --- a/engine/storage_redis.go +++ b/engine/storage_redis.go @@ -980,11 +980,14 @@ func (rs *RedisStorage) RemoveActionTriggers(key string, transactionID string) ( func (rs *RedisStorage) GetActionPlan(key string, skipCache bool, transactionID string) (ats *ActionPlan, err error) { key = utils.ACTION_PLAN_PREFIX + key if !skipCache { - if x, ok := cache.Get(key); ok { - if x != nil { - return x.(*ActionPlan), nil + if x, err := cache.GetCloned(key); err != nil { + if err.Error() != utils.ItemNotFound { // Only consider cache if item was found + return nil, err } + } else if x == nil { // item was placed nil in cache return nil, utils.ErrNotFound + } else { + return x.(*ActionPlan), nil } } var values []byte