diff --git a/apier/v1/api_interfaces.go b/apier/v1/api_interfaces.go index 891eea282..ab8d77b5b 100644 --- a/apier/v1/api_interfaces.go +++ b/apier/v1/api_interfaces.go @@ -116,6 +116,7 @@ type CacheSv1Interface interface { HasItem(args *utils.ArgsGetCacheItemWithOpts, reply *bool) error GetItemExpiryTime(args *utils.ArgsGetCacheItemWithOpts, reply *time.Time) error RemoveItem(args *utils.ArgsGetCacheItemWithOpts, reply *string) error + RemoveItems(args utils.AttrReloadCacheWithOpts, reply *string) error Clear(cacheIDs *utils.AttrCacheIDsWithOpts, reply *string) error GetCacheStats(cacheIDs *utils.AttrCacheIDsWithOpts, rply *map[string]*ltcache.CacheStats) error PrecacheStatus(cacheIDs *utils.AttrCacheIDsWithOpts, rply *map[string]string) error diff --git a/apier/v1/apier.go b/apier/v1/apier.go index 0eab7a65f..2dc754291 100644 --- a/apier/v1/apier.go +++ b/apier/v1/apier.go @@ -1340,39 +1340,41 @@ func (apierSv1 *APIerSv1) ReplayFailedPosts(args *ArgsReplyFailedPosts, reply *s // CallCache caching the item based on cacheopt // visible in APIerSv2 -func (apierSv1 *APIerSv1) CallCache(cacheOpt string, args utils.ArgsGetCacheItem, opts map[string]interface{}) (err error) { - var reply string +func (apierSv1 *APIerSv1) CallCache(cacheopt *string, tnt, cacheID, itemID string, filters *[]string, contexts []string, opts map[string]interface{}) (err error) { + var reply, method string + var args interface{} + cacheOpt := apierSv1.Config.GeneralCfg().DefaultCaching + if cacheopt != nil && *cacheopt != utils.EmptyString { + cacheOpt = *cacheopt + } switch cacheOpt { case utils.META_NONE: return case utils.MetaReload: - if err = apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil, - utils.CacheSv1ReloadCache, utils.AttrReloadCacheWithOpts{ - ArgsCache: composeArgsReload(args), Opts: opts}, &reply); err != nil { - return err + method = utils.CacheSv1ReloadCache + if args, err = apierSv1.composeArgsReload(tnt, cacheID, itemID, filters, contexts, opts); err != nil { + return } case utils.MetaLoad: - if err = apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil, - utils.CacheSv1LoadCache, utils.AttrReloadCacheWithOpts{ - ArgsCache: composeArgsReload(args), Opts: opts}, &reply); err != nil { - return err + method = utils.CacheSv1LoadCache + if args, err = apierSv1.composeArgsReload(tnt, cacheID, itemID, filters, contexts, opts); err != nil { + return } case utils.MetaRemove: - if err = apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil, - utils.CacheSv1RemoveItem, - &utils.ArgsGetCacheItemWithOpts{ArgsGetCacheItem: args, Opts: opts}, &reply); err != nil { - return err + method = utils.CacheSv1RemoveItems + if args, err = apierSv1.composeArgsReload(tnt, cacheID, itemID, filters, contexts, opts); err != nil { + return } case utils.MetaClear: - if err = apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil, - utils.CacheSv1Clear, &utils.AttrCacheIDsWithOpts{ - CacheIDs: []string{args.CacheID}, - Opts: opts, - }, &reply); err != nil { - return err + method = utils.CacheSv1Clear + args = &utils.AttrCacheIDsWithOpts{ + TenantArg: utils.TenantArg{Tenant: tnt}, + CacheIDs: []string{cacheID, utils.CacheInstanceToCacheIndex[cacheID]}, + Opts: opts, } } - return + return apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil, + method, args, &reply) } func (apierSv1 *APIerSv1) GetLoadIDs(args *string, reply *map[string]int64) (err error) { diff --git a/apier/v1/attributes.go b/apier/v1/attributes.go index f1fe2f0e4..0be4ad676 100644 --- a/apier/v1/attributes.go +++ b/apier/v1/attributes.go @@ -111,11 +111,9 @@ func (apierSv1 *APIerSv1) SetAttributeProfile(alsWrp *AttributeWithCache, reply if err := apierSv1.DataManager.SetLoadIDs(map[string]int64{utils.CacheAttributeProfiles: time.Now().UnixNano()}); err != nil { return utils.APIErrorHandler(err) } - args := utils.ArgsGetCacheItem{ - CacheID: utils.CacheAttributeProfiles, - ItemID: alsWrp.TenantID(), - } - if err := apierSv1.CallCache(GetCacheOpt(alsWrp.Cache), args, alsWrp.Opts); err != nil { + + if err := apierSv1.CallCache(alsWrp.Cache, alsWrp.Tenant, utils.CacheAttributeProfiles, + alsWrp.TenantID(), &alsWrp.FilterIDs, alsWrp.Contexts, alsWrp.Opts); err != nil { return utils.APIErrorHandler(err) } *reply = utils.OK @@ -135,11 +133,8 @@ func (apierSv1 *APIerSv1) RemoveAttributeProfile(arg *utils.TenantIDWithCache, r if err := apierSv1.DataManager.SetLoadIDs(map[string]int64{utils.CacheAttributeProfiles: time.Now().UnixNano()}); err != nil { return utils.APIErrorHandler(err) } - args := utils.ArgsGetCacheItem{ - CacheID: utils.CacheAttributeProfiles, - ItemID: utils.ConcatenatedKey(arg.Tenant, arg.ID), - } - if err := apierSv1.CallCache(GetCacheOpt(arg.Cache), args, arg.Opts); err != nil { + if err := apierSv1.CallCache(arg.Cache, arg.Tenant, utils.CacheAttributeProfiles, + utils.ConcatenatedKey(arg.Tenant, arg.ID), nil, nil, arg.Opts); err != nil { return utils.APIErrorHandler(err) } *reply = utils.OK diff --git a/apier/v1/caches.go b/apier/v1/caches.go index dbf651949..04cd03576 100644 --- a/apier/v1/caches.go +++ b/apier/v1/caches.go @@ -59,6 +59,12 @@ func (chSv1 *CacheSv1) RemoveItem(args *utils.ArgsGetCacheItemWithOpts, return chSv1.cacheS.V1RemoveItem(args, reply) } +// RemoveItems removes the Items with ID from cache +func (chSv1 *CacheSv1) RemoveItems(args utils.AttrReloadCacheWithOpts, + reply *string) error { + return chSv1.cacheS.V1RemoveItems(args, reply) +} + // Clear will clear partitions in the cache (nil fol all, empty slice for none) func (chSv1 *CacheSv1) Clear(args *utils.AttrCacheIDsWithOpts, reply *string) error { diff --git a/apier/v1/chargers.go b/apier/v1/chargers.go index 605d93817..20ec9db3d 100644 --- a/apier/v1/chargers.go +++ b/apier/v1/chargers.go @@ -78,11 +78,8 @@ func (apierSv1 *APIerSv1) SetChargerProfile(arg *ChargerWithCache, reply *string return utils.APIErrorHandler(err) } //handle caching for ChargerProfile - argCache := utils.ArgsGetCacheItem{ - CacheID: utils.CacheChargerProfiles, - ItemID: arg.TenantID(), - } - if err := apierSv1.CallCache(GetCacheOpt(arg.Cache), argCache, arg.Opts); err != nil { + if err := apierSv1.CallCache(arg.Cache, arg.Tenant, utils.CacheChargerProfiles, + arg.TenantID(), &arg.FilterIDs, nil, arg.Opts); err != nil { return utils.APIErrorHandler(err) } *reply = utils.OK @@ -103,11 +100,8 @@ func (apierSv1 *APIerSv1) RemoveChargerProfile(arg *utils.TenantIDWithCache, rep return utils.APIErrorHandler(err) } //handle caching for ChargerProfile - argCache := utils.ArgsGetCacheItem{ - CacheID: utils.CacheChargerProfiles, - ItemID: arg.TenantID(), - } - if err := apierSv1.CallCache(GetCacheOpt(arg.Cache), argCache, arg.Opts); err != nil { + if err := apierSv1.CallCache(arg.Cache, arg.Tenant, utils.CacheChargerProfiles, + arg.TenantID(), nil, nil, arg.Opts); err != nil { return utils.APIErrorHandler(err) } *reply = utils.OK diff --git a/apier/v1/dispatcher.go b/apier/v1/dispatcher.go index 93047b1bd..3032c537f 100755 --- a/apier/v1/dispatcher.go +++ b/apier/v1/dispatcher.go @@ -83,11 +83,8 @@ func (apierSv1 *APIerSv1) SetDispatcherProfile(args *DispatcherWithCache, reply return utils.APIErrorHandler(err) } //handle caching for DispatcherProfile - argCache := utils.ArgsGetCacheItem{ - CacheID: utils.CacheDispatcherProfiles, - ItemID: args.TenantID(), - } - if err := apierSv1.CallCache(GetCacheOpt(args.Cache), argCache, args.Opts); err != nil { + if err := apierSv1.CallCache(args.Cache, args.Tenant, utils.CacheDispatcherProfiles, + args.TenantID(), &args.FilterIDs, args.Subsystems, args.Opts); err != nil { return utils.APIErrorHandler(err) } *reply = utils.OK @@ -108,11 +105,8 @@ func (apierSv1 *APIerSv1) RemoveDispatcherProfile(arg *utils.TenantIDWithCache, return utils.APIErrorHandler(err) } //handle caching for DispatcherProfile - argCache := utils.ArgsGetCacheItem{ - CacheID: utils.CacheDispatcherProfiles, - ItemID: arg.TenantID(), - } - if err := apierSv1.CallCache(GetCacheOpt(arg.Cache), argCache, arg.Opts); err != nil { + if err := apierSv1.CallCache(arg.Cache, arg.Tenant, utils.CacheDispatcherProfiles, + arg.TenantID(), nil, nil, arg.Opts); err != nil { return utils.APIErrorHandler(err) } *reply = utils.OK @@ -173,11 +167,8 @@ func (apierSv1 *APIerSv1) SetDispatcherHost(args *DispatcherHostWithCache, reply return utils.APIErrorHandler(err) } //handle caching for DispatcherProfile - argCache := utils.ArgsGetCacheItem{ - CacheID: utils.CacheDispatcherHosts, - ItemID: args.TenantID(), - } - if err := apierSv1.CallCache(GetCacheOpt(args.Cache), argCache, args.Opts); err != nil { + if err := apierSv1.CallCache(args.Cache, args.Tenant, utils.CacheDispatcherHosts, + args.TenantID(), nil, nil, args.Opts); err != nil { return utils.APIErrorHandler(err) } *reply = utils.OK @@ -198,11 +189,8 @@ func (apierSv1 *APIerSv1) RemoveDispatcherHost(arg *utils.TenantIDWithCache, rep return utils.APIErrorHandler(err) } //handle caching for DispatcherProfile - argCache := utils.ArgsGetCacheItem{ - CacheID: utils.CacheDispatcherHosts, - ItemID: arg.TenantID(), - } - if err := apierSv1.CallCache(GetCacheOpt(arg.Cache), argCache, arg.Opts); err != nil { + if err := apierSv1.CallCache(arg.Cache, arg.Tenant, utils.CacheDispatcherHosts, + arg.TenantID(), nil, nil, arg.Opts); err != nil { return utils.APIErrorHandler(err) } *reply = utils.OK @@ -604,6 +592,12 @@ func (dS *DispatcherCacheSv1) RemoveItem(args *utils.ArgsGetCacheItemWithOpts, return dS.dS.CacheSv1RemoveItem(args, reply) } +// RemoveItems removes the Item with ID from cache +func (dS *DispatcherCacheSv1) RemoveItems(args utils.AttrReloadCacheWithOpts, + reply *string) error { + return dS.dS.CacheSv1RemoveItems(args, reply) +} + // Clear will clear partitions in the cache (nil fol all, empty slice for none) func (dS *DispatcherCacheSv1) Clear(args *utils.AttrCacheIDsWithOpts, reply *string) error { diff --git a/apier/v1/filters.go b/apier/v1/filters.go index 4c9c21a37..dfae09f8f 100644 --- a/apier/v1/filters.go +++ b/apier/v1/filters.go @@ -44,11 +44,8 @@ func (apierSv1 *APIerSv1) SetFilter(arg *FilterWithCache, reply *string) error { return utils.APIErrorHandler(err) } //handle caching for Filter - argCache := utils.ArgsGetCacheItem{ - CacheID: utils.CacheFilters, - ItemID: arg.TenantID(), - } - if err := apierSv1.CallCache(GetCacheOpt(arg.Cache), argCache, arg.Opts); err != nil { + if err := apierSv1.CallCache(arg.Cache, arg.Tenant, utils.CacheFilters, + arg.TenantID(), nil, nil, arg.Opts); err != nil { return utils.APIErrorHandler(err) } *reply = utils.OK @@ -102,11 +99,8 @@ func (apierSv1 *APIerSv1) RemoveFilter(arg *utils.TenantIDWithCache, reply *stri return utils.APIErrorHandler(err) } //handle caching for Filter - argCache := utils.ArgsGetCacheItem{ - CacheID: utils.CacheFilters, - ItemID: arg.TenantID(), - } - if err := apierSv1.CallCache(GetCacheOpt(arg.Cache), argCache, arg.Opts); err != nil { + if err := apierSv1.CallCache(arg.Cache, arg.Tenant, utils.CacheFilters, + arg.TenantID(), nil, nil, arg.Opts); err != nil { return utils.APIErrorHandler(err) } *reply = utils.OK diff --git a/apier/v1/libapier.go b/apier/v1/libapier.go index 369719a17..1bb5120ce 100644 --- a/apier/v1/libapier.go +++ b/apier/v1/libapier.go @@ -19,52 +19,75 @@ along with this program. If not, see package v1 import ( - "github.com/cgrates/cgrates/config" + "strings" + + "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) -// GetCacheOpt receive the apiOpt and compare with default value -// overwrite the default if it's present -// visible in APIerSv2 -func GetCacheOpt(apiOpt *string) string { - cacheOpt := config.CgrConfig().GeneralCfg().DefaultCaching - if apiOpt != nil && *apiOpt != utils.EmptyString { - cacheOpt = *apiOpt - } - return cacheOpt -} - // composeArgsReload add the ItemID to AttrReloadCache // for a specific CacheID -func composeArgsReload(args utils.ArgsGetCacheItem) (rpl map[string][]string) { - rpl = make(map[string][]string) - switch args.CacheID { - case utils.CacheResourceProfiles: - rpl[utils.ResourceProfileIDs] = []string{args.ItemID} - case utils.CacheResources: - rpl[utils.ResourceIDs] = []string{args.ItemID} - case utils.CacheStatQueues: - rpl[utils.StatsQueueIDs] = []string{args.ItemID} - case utils.CacheStatQueueProfiles: - rpl[utils.StatsQueueProfileIDs] = []string{args.ItemID} - case utils.CacheThresholds: - rpl[utils.ThresholdIDs] = []string{args.ItemID} - case utils.CacheThresholdProfiles: - rpl[utils.ThresholdProfileIDs] = []string{args.ItemID} - case utils.CacheFilters: - rpl[utils.FilterIDs] = []string{args.ItemID} - case utils.CacheRouteProfiles: - rpl[utils.RouteProfileIDs] = []string{args.ItemID} - case utils.CacheAttributeProfiles: - rpl[utils.AttributeProfileIDs] = []string{args.ItemID} - case utils.CacheChargerProfiles: - rpl[utils.ChargerProfileIDs] = []string{args.ItemID} - case utils.CacheDispatcherProfiles: - rpl[utils.DispatcherProfileIDs] = []string{args.ItemID} - case utils.CacheDispatcherHosts: - rpl[utils.DispatcherHostIDs] = []string{args.ItemID} - case utils.CacheRateProfiles: - rpl[utils.RateProfileIDs] = []string{args.ItemID} +func (apierSv1 *APIerSv1) composeArgsReload(tnt, cacheID, itemID string, filterIDs *[]string, contexts []string, opts map[string]interface{}) (rpl utils.AttrReloadCacheWithOpts, err error) { + rpl = utils.AttrReloadCacheWithOpts{ + TenantArg: utils.TenantArg{Tenant: tnt}, + ArgsCache: map[string][]string{ + utils.CacheInstanceToArg[cacheID]: {itemID}, + }, + Opts: opts, + } + if filterIDs == nil { // in case we remove a profile we do not need to reload the indexes + return + } + // popultate the indexes + idxCacheID := utils.CacheInstanceToCacheIndex[cacheID] + if len(*filterIDs) == 0 { // in case we do not have any filters reload the *none filter indexes + indxID := utils.ConcatenatedKey(utils.META_NONE, utils.META_ANY, utils.META_ANY) + if cacheID != utils.CacheAttributeProfiles && + cacheID != utils.CacheDispatcherProfiles { + rpl.ArgsCache[idxCacheID] = []string{utils.ConcatenatedKey(tnt, indxID)} + return + } + rpl.ArgsCache[idxCacheID] = make([]string, len(contexts)) + for i, ctx := range contexts { + rpl.ArgsCache[idxCacheID][i] = utils.ConcatenatedKey(tnt, ctx, indxID) + } + } + indxIDs := make([]string, 0, len(*filterIDs)) + for _, id := range *filterIDs { + var fltr *engine.Filter + if fltr, err = apierSv1.DataManager.GetFilter(tnt, id, true, true, utils.NonTransactional); err != nil { + return + } + for _, flt := range fltr.Rules { + if !engine.FilterIndexTypes.Has(flt.Type) { + continue + } + isDyn := strings.HasPrefix(flt.Element, utils.DynamicDataPrefix) + for _, fldVal := range flt.Values { + if isDyn { + if !strings.HasPrefix(fldVal, utils.DynamicDataPrefix) { + indxIDs = append(indxIDs, utils.ConcatenatedKey(flt.Type, flt.Element[1:], fldVal)) + } + } else if strings.HasPrefix(fldVal, utils.DynamicDataPrefix) { + indxIDs = append(indxIDs, utils.ConcatenatedKey(flt.Type, fldVal[1:], flt.Element)) + } + } + } + } + if cacheID != utils.CacheAttributeProfiles && + cacheID != utils.CacheDispatcherProfiles { + rpl.ArgsCache[idxCacheID] = make([]string, len(indxIDs)) + for i, indxID := range indxIDs { + rpl.ArgsCache[idxCacheID][i] = utils.ConcatenatedKey(tnt, indxID) + } + return + } + + rpl.ArgsCache[idxCacheID] = make([]string, 0, len(indxIDs)*len(indxIDs)) + for _, ctx := range contexts { + for _, indxID := range indxIDs { + rpl.ArgsCache[idxCacheID] = append(rpl.ArgsCache[idxCacheID], utils.ConcatenatedKey(tnt, ctx, indxID)) + } } return } diff --git a/apier/v1/rateprofiles.go b/apier/v1/rateprofiles.go index 275e06d13..a1c3cd0e0 100644 --- a/apier/v1/rateprofiles.go +++ b/apier/v1/rateprofiles.go @@ -100,11 +100,8 @@ func (apierSv1 *APIerSv1) SetRateProfile(rPrf *RateProfileWithCache, reply *stri if err := apierSv1.DataManager.SetLoadIDs(map[string]int64{utils.CacheRateProfiles: time.Now().UnixNano()}); err != nil { return utils.APIErrorHandler(err) } - args := utils.ArgsGetCacheItem{ - CacheID: utils.CacheRateProfiles, - ItemID: rPrf.TenantID(), - } - if err := apierSv1.CallCache(GetCacheOpt(rPrf.Cache), args, rPrf.Opts); err != nil { + if err := apierSv1.CallCache(rPrf.Cache, rPrf.Tenant, utils.CacheRateProfiles, + rPrf.TenantID(), &rPrf.FilterIDs, nil, rPrf.Opts); err != nil { return utils.APIErrorHandler(err) } *reply = utils.OK @@ -124,11 +121,8 @@ func (apierSv1 *APIerSv1) SetRateProfileRates(rPrf *RateProfileWithCache, reply if err = apierSv1.DataManager.SetLoadIDs(map[string]int64{utils.CacheRateProfiles: time.Now().UnixNano()}); err != nil { return utils.APIErrorHandler(err) } - args := utils.ArgsGetCacheItem{ - CacheID: utils.CacheRateProfiles, - ItemID: rPrf.TenantID(), - } - if err = apierSv1.CallCache(GetCacheOpt(rPrf.Cache), args, rPrf.Opts); err != nil { + if err = apierSv1.CallCache(rPrf.Cache, rPrf.Tenant, utils.CacheRateProfiles, + rPrf.TenantID(), &rPrf.FilterIDs, nil, rPrf.Opts); err != nil { return utils.APIErrorHandler(err) } *reply = utils.OK @@ -154,11 +148,8 @@ func (apierSv1 *APIerSv1) RemoveRateProfileRates(args *RemoveRPrfRates, reply *s if err := apierSv1.DataManager.SetLoadIDs(map[string]int64{utils.CacheRateProfiles: time.Now().UnixNano()}); err != nil { return utils.APIErrorHandler(err) } - argsCache := utils.ArgsGetCacheItem{ - CacheID: utils.CacheRateProfiles, - ItemID: utils.ConcatenatedKey(args.Tenant, args.ID), - } - if err := apierSv1.CallCache(GetCacheOpt(args.Cache), argsCache, args.Opts); err != nil { + if err := apierSv1.CallCache(args.Cache, args.Tenant, utils.CacheRateProfiles, + utils.ConcatenatedKey(args.Tenant, args.ID), nil, nil, args.Opts); err != nil { return utils.APIErrorHandler(err) } *reply = utils.OK @@ -178,11 +169,8 @@ func (apierSv1 *APIerSv1) RemoveRateProfile(arg *utils.TenantIDWithCache, reply if err := apierSv1.DataManager.SetLoadIDs(map[string]int64{utils.CacheRateProfiles: time.Now().UnixNano()}); err != nil { return utils.APIErrorHandler(err) } - args := utils.ArgsGetCacheItem{ - CacheID: utils.CacheRateProfiles, - ItemID: utils.ConcatenatedKey(arg.Tenant, arg.ID), - } - if err := apierSv1.CallCache(GetCacheOpt(arg.Cache), args, arg.Opts); err != nil { + if err := apierSv1.CallCache(arg.Cache, arg.Tenant, utils.CacheRateProfiles, + utils.ConcatenatedKey(arg.Tenant, arg.ID), nil, nil, arg.Opts); err != nil { return utils.APIErrorHandler(err) } *reply = utils.OK diff --git a/apier/v1/resourcesv1.go b/apier/v1/resourcesv1.go index 0d45118ff..24f82f1e6 100644 --- a/apier/v1/resourcesv1.go +++ b/apier/v1/resourcesv1.go @@ -121,11 +121,8 @@ func (apierSv1 *APIerSv1) SetResourceProfile(arg *ResourceWithCache, reply *stri return utils.APIErrorHandler(err) } //handle caching for ResourceProfile - argCache := utils.ArgsGetCacheItem{ - CacheID: utils.CacheResourceProfiles, - ItemID: arg.TenantID(), - } - if err := apierSv1.CallCache(GetCacheOpt(arg.Cache), argCache, arg.Opts); err != nil { + if err := apierSv1.CallCache(arg.Cache, arg.Tenant, utils.CacheResourceProfiles, + arg.TenantID(), &arg.FilterIDs, nil, arg.Opts); err != nil { return utils.APIErrorHandler(err) } //add the resource only if it's not present @@ -139,11 +136,8 @@ func (apierSv1 *APIerSv1) SetResourceProfile(arg *ResourceWithCache, reply *stri return utils.APIErrorHandler(err) } //handle caching for Resource - argCache = utils.ArgsGetCacheItem{ - CacheID: utils.CacheResources, - ItemID: arg.TenantID(), - } - if err := apierSv1.CallCache(GetCacheOpt(arg.Cache), argCache, arg.Opts); err != nil { + if err := apierSv1.CallCache(arg.Cache, arg.Tenant, utils.CacheResources, + arg.TenantID(), nil, nil, arg.Opts); err != nil { return utils.APIErrorHandler(err) } } @@ -161,11 +155,8 @@ func (apierSv1 *APIerSv1) RemoveResourceProfile(arg *utils.TenantIDWithCache, re return utils.APIErrorHandler(err) } //handle caching for ResourceProfile - argCache := utils.ArgsGetCacheItem{ - CacheID: utils.CacheResourceProfiles, - ItemID: arg.TenantID(), - } - if err := apierSv1.CallCache(GetCacheOpt(arg.Cache), argCache, arg.Opts); err != nil { + if err := apierSv1.CallCache(arg.Cache, arg.Tenant, utils.CacheResourceProfiles, + arg.TenantID(), nil, nil, arg.Opts); err != nil { return utils.APIErrorHandler(err) } if err := apierSv1.DataManager.RemoveResource(arg.Tenant, arg.ID, utils.NonTransactional); err != nil { @@ -178,11 +169,8 @@ func (apierSv1 *APIerSv1) RemoveResourceProfile(arg *utils.TenantIDWithCache, re return utils.APIErrorHandler(err) } //handle caching for Resource - argCache = utils.ArgsGetCacheItem{ - CacheID: utils.CacheResources, - ItemID: arg.TenantID(), - } - if err := apierSv1.CallCache(GetCacheOpt(arg.Cache), argCache, arg.Opts); err != nil { + if err := apierSv1.CallCache(arg.Cache, arg.Tenant, utils.CacheResources, + arg.TenantID(), nil, nil, arg.Opts); err != nil { return utils.APIErrorHandler(err) } *reply = utils.OK diff --git a/apier/v1/routes.go b/apier/v1/routes.go index facb3e254..7f62bb00f 100644 --- a/apier/v1/routes.go +++ b/apier/v1/routes.go @@ -78,11 +78,8 @@ func (apierSv1 *APIerSv1) SetRouteProfile(args *RouteWithCache, reply *string) e return utils.APIErrorHandler(err) } //handle caching for SupplierProfile - argCache := utils.ArgsGetCacheItem{ - CacheID: utils.CacheRouteProfiles, - ItemID: args.TenantID(), - } - if err := apierSv1.CallCache(GetCacheOpt(args.Cache), argCache, args.Opts); err != nil { + if err := apierSv1.CallCache(args.Cache, args.Tenant, utils.CacheRouteProfiles, + args.TenantID(), &args.FilterIDs, nil, args.Opts); err != nil { return utils.APIErrorHandler(err) } *reply = utils.OK @@ -102,11 +99,8 @@ func (apierSv1 *APIerSv1) RemoveRouteProfile(args *utils.TenantIDWithCache, repl return utils.APIErrorHandler(err) } //handle caching for SupplierProfile - argCache := utils.ArgsGetCacheItem{ - CacheID: utils.CacheRouteProfiles, - ItemID: args.TenantID(), - } - if err := apierSv1.CallCache(GetCacheOpt(args.Cache), argCache, args.Opts); err != nil { + if err := apierSv1.CallCache(args.Cache, args.Tenant, utils.CacheRouteProfiles, + args.TenantID(), nil, nil, args.Opts); err != nil { return utils.APIErrorHandler(err) } *reply = utils.OK diff --git a/apier/v1/stats.go b/apier/v1/stats.go index b9069bb8f..64bc885da 100644 --- a/apier/v1/stats.go +++ b/apier/v1/stats.go @@ -75,11 +75,8 @@ func (apierSv1 *APIerSv1) SetStatQueueProfile(arg *engine.StatQueueWithCache, re return utils.APIErrorHandler(err) } //handle caching for StatQueueProfile - argCache := utils.ArgsGetCacheItem{ - CacheID: utils.CacheStatQueueProfiles, - ItemID: arg.TenantID(), - } - if err := apierSv1.CallCache(GetCacheOpt(arg.Cache), argCache, arg.Opts); err != nil { + if err := apierSv1.CallCache(arg.Cache, arg.Tenant, utils.CacheStatQueueProfiles, + arg.TenantID(), &arg.FilterIDs, nil, arg.Opts); err != nil { return utils.APIErrorHandler(err) } if has, err := apierSv1.DataManager.HasData(utils.StatQueuePrefix, arg.ID, arg.Tenant); err != nil { @@ -98,11 +95,8 @@ func (apierSv1 *APIerSv1) SetStatQueueProfile(arg *engine.StatQueueWithCache, re return utils.APIErrorHandler(err) } //handle caching for StatQueues - argCache = utils.ArgsGetCacheItem{ - CacheID: utils.CacheStatQueues, - ItemID: arg.TenantID(), - } - if err := apierSv1.CallCache(GetCacheOpt(arg.Cache), argCache, arg.Opts); err != nil { + if err := apierSv1.CallCache(arg.Cache, arg.Tenant, utils.CacheStatQueues, + arg.TenantID(), nil, nil, arg.Opts); err != nil { return utils.APIErrorHandler(err) } } @@ -120,11 +114,8 @@ func (apierSv1 *APIerSv1) RemoveStatQueueProfile(args *utils.TenantIDWithCache, return utils.APIErrorHandler(err) } //handle caching for StatQueueProfile - argCache := utils.ArgsGetCacheItem{ - CacheID: utils.CacheStatQueueProfiles, - ItemID: args.TenantID(), - } - if err := apierSv1.CallCache(GetCacheOpt(args.Cache), argCache, args.Opts); err != nil { + if err := apierSv1.CallCache(args.Cache, args.Tenant, utils.CacheStatQueueProfiles, + args.TenantID(), nil, nil, args.Opts); err != nil { return utils.APIErrorHandler(err) } if err := apierSv1.DataManager.RemoveStatQueue(args.Tenant, args.ID, utils.NonTransactional); err != nil { @@ -137,11 +128,8 @@ func (apierSv1 *APIerSv1) RemoveStatQueueProfile(args *utils.TenantIDWithCache, return utils.APIErrorHandler(err) } //handle caching for StatQueues - argCache = utils.ArgsGetCacheItem{ - CacheID: utils.CacheStatQueues, - ItemID: args.TenantID(), - } - if err := apierSv1.CallCache(GetCacheOpt(args.Cache), argCache, args.Opts); err != nil { + if err := apierSv1.CallCache(args.Cache, args.Tenant, utils.CacheStatQueues, + args.TenantID(), nil, nil, args.Opts); err != nil { return utils.APIErrorHandler(err) } *reply = utils.OK diff --git a/apier/v1/thresholds.go b/apier/v1/thresholds.go index 1effd84d4..bf689b9f2 100644 --- a/apier/v1/thresholds.go +++ b/apier/v1/thresholds.go @@ -127,11 +127,8 @@ func (apierSv1 *APIerSv1) SetThresholdProfile(args *engine.ThresholdWithCache, r return utils.APIErrorHandler(err) } //handle caching for ThresholdProfile - argCache := utils.ArgsGetCacheItem{ - CacheID: utils.CacheThresholdProfiles, - ItemID: args.TenantID(), - } - if err := apierSv1.CallCache(GetCacheOpt(args.Cache), argCache, args.Opts); err != nil { + if err := apierSv1.CallCache(args.Cache, args.Tenant, utils.CacheThresholdProfiles, + args.TenantID(), &args.FilterIDs, nil, args.Opts); err != nil { return utils.APIErrorHandler(err) } @@ -142,11 +139,8 @@ func (apierSv1 *APIerSv1) SetThresholdProfile(args *engine.ThresholdWithCache, r return err } //handle caching for Threshold - argCache = utils.ArgsGetCacheItem{ - CacheID: utils.CacheThresholds, - ItemID: args.TenantID(), - } - if err := apierSv1.CallCache(GetCacheOpt(args.Cache), argCache, args.Opts); err != nil { + if err := apierSv1.CallCache(args.Cache, args.Tenant, utils.CacheThresholds, + args.TenantID(), nil, nil, args.Opts); err != nil { return utils.APIErrorHandler(err) } } @@ -164,11 +158,8 @@ func (apierSv1 *APIerSv1) RemoveThresholdProfile(args *utils.TenantIDWithCache, return utils.APIErrorHandler(err) } //handle caching for ThresholdProfile - argCache := utils.ArgsGetCacheItem{ - CacheID: utils.CacheThresholdProfiles, - ItemID: args.TenantID(), - } - if err := apierSv1.CallCache(GetCacheOpt(args.Cache), argCache, args.Opts); err != nil { + if err := apierSv1.CallCache(args.Cache, args.Tenant, utils.CacheThresholdProfiles, + args.TenantID(), nil, nil, args.Opts); err != nil { return utils.APIErrorHandler(err) } if err := apierSv1.DataManager.RemoveThreshold(args.Tenant, args.ID, utils.NonTransactional); err != nil { @@ -181,11 +172,8 @@ func (apierSv1 *APIerSv1) RemoveThresholdProfile(args *utils.TenantIDWithCache, return utils.APIErrorHandler(err) } //handle caching for Threshold - argCache = utils.ArgsGetCacheItem{ - CacheID: utils.CacheThresholds, - ItemID: args.TenantID(), - } - if err := apierSv1.CallCache(GetCacheOpt(args.Cache), argCache, args.Opts); err != nil { + if err := apierSv1.CallCache(args.Cache, args.Tenant, utils.CacheThresholds, + args.TenantID(), nil, nil, args.Opts); err != nil { return utils.APIErrorHandler(err) } *reply = utils.OK diff --git a/apier/v2/attributes.go b/apier/v2/attributes.go index de73c421a..210b7a01d 100644 --- a/apier/v2/attributes.go +++ b/apier/v2/attributes.go @@ -21,7 +21,6 @@ package v2 import ( "time" - v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -49,13 +48,8 @@ func (APIerSv2 *APIerSv2) SetAttributeProfile(arg *AttributeWithCache, reply *st map[string]int64{utils.CacheAttributeProfiles: time.Now().UnixNano()}); err != nil { return utils.APIErrorHandler(err) } - args := utils.ArgsGetCacheItem{ - CacheID: utils.CacheAttributeProfiles, - ItemID: alsPrf.TenantID(), - } - if err := APIerSv2.APIerSv1.CallCache( - v1.GetCacheOpt(arg.Cache), - args, arg.Opts); err != nil { + if err := APIerSv2.APIerSv1.CallCache(arg.Cache, alsPrf.Tenant, utils.CacheAttributeProfiles, + alsPrf.TenantID(), &alsPrf.FilterIDs, alsPrf.Contexts, arg.Opts); err != nil { return utils.APIErrorHandler(err) } *reply = utils.OK diff --git a/data/tariffplans/dispatchers/Attributes.csv b/data/tariffplans/dispatchers/Attributes.csv index 9d2a52072..0847a6528 100644 --- a/data/tariffplans/dispatchers/Attributes.csv +++ b/data/tariffplans/dispatchers/Attributes.csv @@ -11,7 +11,7 @@ cgrates.org,ATTR_API_STAT_AUTH,*auth,*string:~*req.ApiKey:stat12345,,,*req.APIMe cgrates.org,ATTR_API_RES_AUTH,*auth,*string:~*req.ApiKey:res12345,,,*req.APIMethods,*constant,ResourceSv1.Ping&ResourceSv1.GetResourcesForEvent&ResourceSv1.AuthorizeResources&ResourceSv1.AllocateResources&ResourceSv1.ReleaseResources&ResourceSv1.GetResource,false,20 cgrates.org,ATTR_API_SES_AUTH,*auth,*string:~*req.ApiKey:ses12345,,,*req.APIMethods,*constant,SessionSv1.Ping&SessionSv1.AuthorizeEvent&SessionSv1.AuthorizeEventWithDigest&SessionSv1.InitiateSession&SessionSv1.InitiateSessionWithDigest&SessionSv1.UpdateSession&SessionSv1.SyncSessions&SessionSv1.TerminateSession&SessionSv1.ProcessCDR&SessionSv1.ProcessMessage&SessionSv1.GetActiveSessions&SessionSv1.GetActiveSessionsCount&SessionSv1.ForceDisconnect&SessionSv1.GetPassiveSessions&SessionSv1.GetPassiveSessionsCount&SessionSv1.ReplicateSessions&SessionSv1.SetPassiveSession&SessionSv1.ProcessEvent&SessionSv1.GetCost&SessionSv1.STIRAuthenticate&SessionSv1.STIRIdentity,false,20 cgrates.org,ATTR_API_RSP_AUTH,*auth,*string:~*req.ApiKey:rsp12345,,,*req.APIMethods,*constant,CoreSv1.Status&CoreSv1.Ping&Responder.Shutdown&Responder.Ping,false,20 -cgrates.org,ATTR_API_CHC_AUTH,*auth,*string:~*req.ApiKey:chc12345,,,*req.APIMethods,*constant,CacheSv1.Ping&CacheSv1.GetCacheStats&CacheSv1.LoadCache&CacheSv1.PrecacheStatus&CacheSv1.GetItemIDs&CacheSv1.HasItem&CacheSv1.GetItemExpiryTime&CacheSv1.ReloadCache&CacheSv1.RemoveItem&CacheSv1.Clear,false,20 +cgrates.org,ATTR_API_CHC_AUTH,*auth,*string:~*req.ApiKey:chc12345,,,*req.APIMethods,*constant,CacheSv1.Ping&CacheSv1.GetCacheStats&CacheSv1.LoadCache&CacheSv1.PrecacheStatus&CacheSv1.GetItemIDs&CacheSv1.HasItem&CacheSv1.GetItemExpiryTime&CacheSv1.ReloadCache&CacheSv1.RemoveItem&CacheSv1.RemoveItems&CacheSv1.Clear,false,20 cgrates.org,ATTR_API_GRD_AUTH,*auth,*string:~*req.ApiKey:grd12345,,,*req.APIMethods,*constant,GuardianSv1.Ping&GuardianSv1.RemoteLock&GuardianSv1.RemoteUnlock,false,20 cgrates.org,ATTR_API_SCHD_AUTH,*auth,*string:~*req.ApiKey:sched12345,,,*req.APIMethods,*constant,SchedulerSv1.Ping,false,20 cgrates.org,ATTR_API_CDRS_AUTH,*auth,*string:~*req.ApiKey:cdrs12345,,,*req.APIMethods,*constant,CDRsV1.Ping&CDRsV1.ProcessEvent&CDRsV1.GetCDRs&CDRsV1.GetCDRsCount&CDRsV1.ProcessCDR&CDRsV1.ProcessExternalCDR,false,20 diff --git a/data/tariffplans/dispatchers_gob/Attributes.csv b/data/tariffplans/dispatchers_gob/Attributes.csv index 1a8b4574a..78225d3bd 100644 --- a/data/tariffplans/dispatchers_gob/Attributes.csv +++ b/data/tariffplans/dispatchers_gob/Attributes.csv @@ -11,7 +11,7 @@ cgrates.org,ATTR_API_STAT_AUTH,*auth,*string:~*req.ApiKey:stat12345,,,*req.APIMe cgrates.org,ATTR_API_RES_AUTH,*auth,*string:~*req.ApiKey:res12345,,,*req.APIMethods,*constant,ResourceSv1.Ping&ResourceSv1.GetResourcesForEvent&ResourceSv1.AuthorizeResources&ResourceSv1.AllocateResources&ResourceSv1.ReleaseResources&ResourceSv1.GetResource,false,20 cgrates.org,ATTR_API_SES_AUTH,*auth,*string:~*req.ApiKey:ses12345,,,*req.APIMethods,*constant,SessionSv1.Ping&SessionSv1.AuthorizeEvent&SessionSv1.AuthorizeEventWithDigest&SessionSv1.InitiateSession&SessionSv1.InitiateSessionWithDigest&SessionSv1.UpdateSession&SessionSv1.SyncSessions&SessionSv1.TerminateSession&SessionSv1.ProcessCDR&SessionSv1.ProcessMessage&SessionSv1.GetActiveSessions&SessionSv1.GetActiveSessionsCount&SessionSv1.ForceDisconnect&SessionSv1.GetPassiveSessions&SessionSv1.GetPassiveSessionsCount&SessionSv1.ReplicateSessions&SessionSv1.SetPassiveSession&SessionSv1.ProcessEvent&SessionSv1.GetCost&SessionSv1.STIRAuthenticate&SessionSv1.STIRIdentity,false,20 cgrates.org,ATTR_API_RSP_AUTH,*auth,*string:~*req.ApiKey:rsp12345,,,*req.APIMethods,*constant,CoreSv1.Status&CoreSv1.Ping&Responder.Shutdown&Responder.Ping,false,20 -cgrates.org,ATTR_API_CHC_AUTH,*auth,*string:~*req.ApiKey:chc12345,,,*req.APIMethods,*constant,CacheSv1.Ping&CacheSv1.GetCacheStats&CacheSv1.LoadCache&CacheSv1.PrecacheStatus&CacheSv1.GetItemIDs&CacheSv1.HasItem&CacheSv1.GetItemExpiryTime&CacheSv1.ReloadCache&CacheSv1.RemoveItem&CacheSv1.Clear,false,20 +cgrates.org,ATTR_API_CHC_AUTH,*auth,*string:~*req.ApiKey:chc12345,,,*req.APIMethods,*constant,CacheSv1.Ping&CacheSv1.GetCacheStats&CacheSv1.LoadCache&CacheSv1.PrecacheStatus&CacheSv1.GetItemIDs&CacheSv1.HasItem&CacheSv1.GetItemExpiryTime&CacheSv1.ReloadCache&CacheSv1.RemoveItem&CacheSv1.RemoveItems&CacheSv1.Clear,false,20 cgrates.org,ATTR_API_GRD_AUTH,*auth,*string:~*req.ApiKey:grd12345,,,*req.APIMethods,*constant,GuardianSv1.Ping&GuardianSv1.RemoteLock&GuardianSv1.RemoteUnlock,false,20 cgrates.org,ATTR_API_SCHD_AUTH,*auth,*string:~*req.ApiKey:sched12345,,,*req.APIMethods,*constant,SchedulerSv1.Ping,false,20 cgrates.org,ATTR_API_CDRS_AUTH,*auth,*string:~*req.ApiKey:cdrs12345,,,*req.APIMethods,*constant,CDRsV1.Ping&CDRsV1.ProcessEvent&CDRsV1.GetCDRs&CDRsV1.GetCDRsCount&CDRsV1.ProcessCDR&CDRsV1.ProcessExternalCDR,false,20 diff --git a/dispatchers/caches.go b/dispatchers/caches.go index efde16d97..fd75b8133 100644 --- a/dispatchers/caches.go +++ b/dispatchers/caches.go @@ -130,6 +130,27 @@ func (dS *DispatcherService) CacheSv1RemoveItem(args *utils.ArgsGetCacheItemWith }, utils.MetaCaches, utils.CacheSv1RemoveItem, args, reply) } +// CacheSv1RemoveItems removes the Item with ID from cache +func (dS *DispatcherService) CacheSv1RemoveItems(args utils.AttrReloadCacheWithOpts, + reply *string) (err error) { + tnt := dS.cfg.GeneralCfg().DefaultTenant + if args.TenantArg.Tenant != utils.EmptyString { + tnt = args.TenantArg.Tenant + } + if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { + if err = dS.authorize(utils.CacheSv1RemoveItems, tnt, + utils.IfaceAsString(args.Opts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil { + return + } + } + return dS.Dispatch(&utils.CGREventWithOpts{ + CGREvent: &utils.CGREvent{ + Tenant: tnt, + }, + Opts: args.Opts, + }, utils.MetaCaches, utils.CacheSv1RemoveItems, args, reply) +} + // CacheSv1Clear will clear partitions in the cache (nil fol all, empty slice for none) func (dS *DispatcherService) CacheSv1Clear(args *utils.AttrCacheIDsWithOpts, reply *string) (err error) { diff --git a/engine/caches.go b/engine/caches.go index 42164c280..253d95edc 100644 --- a/engine/caches.go +++ b/engine/caches.go @@ -271,6 +271,19 @@ func (chS *CacheS) V1RemoveItem(args *utils.ArgsGetCacheItemWithOpts, return } +func (chS *CacheS) V1RemoveItems(args utils.AttrReloadCacheWithOpts, + reply *string) (err error) { + for key, ids := range args.ArgsCache { + if cacheID, has := utils.ArgCacheToInstance[key]; has { + for _, id := range ids { + chS.tCache.Remove(cacheID, id, true, utils.NonTransactional) + } + } + } + *reply = utils.OK + return +} + func (chS *CacheS) V1Clear(args *utils.AttrCacheIDsWithOpts, reply *string) (err error) { chS.tCache.Clear(args.CacheIDs) diff --git a/engine/libindex.go b/engine/libindex.go index 62f15ea74..8ee9a441e 100644 --- a/engine/libindex.go +++ b/engine/libindex.go @@ -28,7 +28,7 @@ import ( ) var ( - filterIndexTypes = utils.NewStringSet([]string{utils.MetaPrefix, utils.MetaString, utils.MetaSuffix}) + FilterIndexTypes = utils.NewStringSet([]string{utils.MetaPrefix, utils.MetaString, utils.MetaSuffix}) ) // newFilterIndex will get the index from DataManager if is not found it will create it @@ -67,7 +67,7 @@ func newFilterIndex(dm *DataManager, idxItmType, tnt, ctx, itemID string, filter return } for _, flt := range fltr.Rules { - if !filterIndexTypes.Has(flt.Type) { + if !FilterIndexTypes.Has(flt.Type) { continue } @@ -477,7 +477,7 @@ func UpdateFilterIndex(dm *DataManager, oldFlt, newFlt *Filter) (err error) { newRules := utils.StringSet{} // we only need to determine if we added new rules to rebuild removeRules := utils.StringSet{} // but we need to know what indexes to remove for _, flt := range newFlt.Rules { - if !filterIndexTypes.Has(flt.Type) { + if !FilterIndexTypes.Has(flt.Type) { continue } isDyn := strings.HasPrefix(flt.Element, utils.DynamicDataPrefix) @@ -498,7 +498,7 @@ func UpdateFilterIndex(dm *DataManager, oldFlt, newFlt *Filter) (err error) { } } for _, flt := range oldFlt.Rules { - if !filterIndexTypes.Has(flt.Type) { + if !FilterIndexTypes.Has(flt.Type) { continue } isDyn := strings.HasPrefix(flt.Element, utils.DynamicDataPrefix) diff --git a/engine/tpreader.go b/engine/tpreader.go index a996368b4..006e2633f 100644 --- a/engine/tpreader.go +++ b/engine/tpreader.go @@ -2479,7 +2479,7 @@ func (tpr *TpReader) ReloadCache(caching string, verbose bool, opts map[string]i return } case utils.MetaRemove: - if err = connMgr.Call(tpr.cacheConns, nil, utils.CacheSv1RemoveItem, cacheArgs, &reply); err != nil { + if err = connMgr.Call(tpr.cacheConns, nil, utils.CacheSv1RemoveItems, cacheArgs, &reply); err != nil { return } case utils.MetaClear: @@ -2515,6 +2515,9 @@ func (tpr *TpReader) ReloadCache(caching string, verbose bool, opts map[string]i cacheIDs = append(cacheIDs, utils.CacheRateProfilesFilterIndexes) cacheIDs = append(cacheIDs, utils.CacheRateFilterIndexes) } + if len(flrIDs) != 0 { + cacheIDs = append(cacheIDs, utils.CacheReverseFilterIndexes) + } if verbose { log.Print("Clearing indexes") } diff --git a/loaders/loader.go b/loaders/loader.go index 1641a7206..850fca878 100644 --- a/loaders/loader.go +++ b/loaders/loader.go @@ -276,7 +276,6 @@ func (ldr *Loader) storeLoadedData(loaderType string, lds map[string][]LoaderData, caching string) (err error) { var ids []string cacheArgs := make(map[string][]string) - var cachePartition string switch loaderType { case utils.MetaAttributes: for _, lDataSet := range lds { @@ -305,7 +304,6 @@ func (ldr *Loader) storeLoadedData(loaderType string, } } cacheArgs[utils.AttributeProfileIDs] = ids - cachePartition = utils.CacheAttributeProfiles } case utils.MetaResources: for _, lDataSet := range lds { @@ -341,7 +339,6 @@ func (ldr *Loader) storeLoadedData(loaderType string, } cacheArgs[utils.ResourceProfileIDs] = ids cacheArgs[utils.ResourceIDs] = ids - cachePartition = utils.CacheResourceProfiles } } case utils.MetaFilters: @@ -371,7 +368,6 @@ func (ldr *Loader) storeLoadedData(loaderType string, return err } cacheArgs[utils.FilterIDs] = ids - cachePartition = utils.CacheFilters } } case utils.MetaStats: @@ -412,7 +408,6 @@ func (ldr *Loader) storeLoadedData(loaderType string, } cacheArgs[utils.StatsQueueProfileIDs] = ids cacheArgs[utils.StatsQueueIDs] = ids - cachePartition = utils.CacheFilters } } case utils.MetaThresholds: @@ -445,7 +440,6 @@ func (ldr *Loader) storeLoadedData(loaderType string, } cacheArgs[utils.ThresholdProfileIDs] = ids cacheArgs[utils.ThresholdIDs] = ids - cachePartition = utils.CacheThresholdProfiles } } case utils.MetaRoutes: @@ -475,7 +469,6 @@ func (ldr *Loader) storeLoadedData(loaderType string, return err } cacheArgs[utils.RouteProfileIDs] = ids - cachePartition = utils.CacheRouteProfiles } } case utils.MetaChargers: @@ -505,7 +498,6 @@ func (ldr *Loader) storeLoadedData(loaderType string, return err } cacheArgs[utils.ChargerProfileIDs] = ids - cachePartition = utils.CacheChargerProfiles } } case utils.MetaDispatchers: @@ -534,7 +526,6 @@ func (ldr *Loader) storeLoadedData(loaderType string, return err } cacheArgs[utils.DispatcherProfileIDs] = ids - cachePartition = utils.CacheDispatcherProfiles } } case utils.MetaDispatcherHosts: @@ -560,7 +551,6 @@ func (ldr *Loader) storeLoadedData(loaderType string, return err } cacheArgs[utils.DispatcherHostIDs] = ids - cachePartition = utils.CacheDispatcherHosts } } case utils.MetaRateProfiles: @@ -595,7 +585,6 @@ func (ldr *Loader) storeLoadedData(loaderType string, } } cacheArgs[utils.RateProfileIDs] = ids - cachePartition = utils.CacheRateProfiles } } } @@ -618,16 +607,10 @@ func (ldr *Loader) storeLoadedData(loaderType string, return } case utils.MetaRemove: - for _, id := range ids { - if err = ldr.connMgr.Call(ldr.cacheConns, nil, - utils.CacheSv1RemoveItem, &utils.ArgsGetCacheItemWithOpts{ - ArgsGetCacheItem: utils.ArgsGetCacheItem{ - CacheID: cachePartition, - ItemID: id, - }, - }, &reply); err != nil { - return - } + if err = ldr.connMgr.Call(ldr.cacheConns, nil, + utils.CacheSv1RemoveItems, utils.AttrReloadCacheWithOpts{ + ArgsCache: cacheArgs}, &reply); err != nil { + return } case utils.MetaClear: if err = ldr.connMgr.Call(ldr.cacheConns, nil, @@ -711,7 +694,6 @@ func (ldr *Loader) removeContent(loaderType, caching string) (err error) { func (ldr *Loader) removeLoadedData(loaderType string, lds map[string][]LoaderData, caching string) (err error) { var ids []string cacheArgs := make(map[string][]string) - var cachePartition string switch loaderType { case utils.MetaAttributes: for tntID := range lds { @@ -728,7 +710,6 @@ func (ldr *Loader) removeLoadedData(loaderType string, lds map[string][]LoaderDa return err } cacheArgs[utils.AttributeProfileIDs] = ids - cachePartition = utils.CacheAttributeProfiles } } @@ -752,7 +733,6 @@ func (ldr *Loader) removeLoadedData(loaderType string, lds map[string][]LoaderDa } cacheArgs[utils.ResourceProfileIDs] = ids cacheArgs[utils.ResourceIDs] = ids - cachePartition = utils.CacheResourceProfiles } } case utils.MetaFilters: @@ -770,7 +750,6 @@ func (ldr *Loader) removeLoadedData(loaderType string, lds map[string][]LoaderDa return err } cacheArgs[utils.FilterIDs] = ids - cachePartition = utils.CacheFilters } } case utils.MetaStats: @@ -792,7 +771,6 @@ func (ldr *Loader) removeLoadedData(loaderType string, lds map[string][]LoaderDa } cacheArgs[utils.StatsQueueProfileIDs] = ids cacheArgs[utils.StatsQueueIDs] = ids - cachePartition = utils.CacheStatQueueProfiles } } case utils.MetaThresholds: @@ -814,7 +792,6 @@ func (ldr *Loader) removeLoadedData(loaderType string, lds map[string][]LoaderDa } cacheArgs[utils.ThresholdProfileIDs] = ids cacheArgs[utils.ThresholdIDs] = ids - cachePartition = utils.CacheThresholdProfiles } } case utils.MetaRoutes: @@ -832,7 +809,6 @@ func (ldr *Loader) removeLoadedData(loaderType string, lds map[string][]LoaderDa return err } cacheArgs[utils.RouteProfileIDs] = ids - cachePartition = utils.CacheRouteProfiles } } case utils.MetaChargers: @@ -850,7 +826,6 @@ func (ldr *Loader) removeLoadedData(loaderType string, lds map[string][]LoaderDa return err } cacheArgs[utils.ChargerProfileIDs] = ids - cachePartition = utils.CacheChargerProfiles } } case utils.MetaDispatchers: @@ -868,7 +843,6 @@ func (ldr *Loader) removeLoadedData(loaderType string, lds map[string][]LoaderDa return err } cacheArgs[utils.DispatcherProfileIDs] = ids - cachePartition = utils.CacheDispatcherProfiles } } case utils.MetaDispatcherHosts: @@ -886,7 +860,6 @@ func (ldr *Loader) removeLoadedData(loaderType string, lds map[string][]LoaderDa return err } cacheArgs[utils.DispatcherHostIDs] = ids - cachePartition = utils.CacheDispatcherHosts } } case utils.MetaRateProfiles: @@ -901,14 +874,13 @@ func (ldr *Loader) removeLoadedData(loaderType string, lds map[string][]LoaderDa ids = append(ids, tntID) if ldr.flagsTpls[loaderType].GetBool(utils.MetaPartial) { - - if rateIDs, err := ldData[0].GetRateIDs(); err != nil { + rateIDs, err := ldData[0].GetRateIDs() + if err != nil { + return err + } + if err := ldr.dm.RemoveRateProfileRates(tntIDStruct.Tenant, + tntIDStruct.ID, rateIDs, true); err != nil { return err - } else { - if err := ldr.dm.RemoveRateProfileRates(tntIDStruct.Tenant, - tntIDStruct.ID, rateIDs, true); err != nil { - return err - } } } else { if err := ldr.dm.RemoveRateProfile(tntIDStruct.Tenant, @@ -918,7 +890,6 @@ func (ldr *Loader) removeLoadedData(loaderType string, lds map[string][]LoaderDa } cacheArgs[utils.RateProfileIDs] = ids - cachePartition = utils.CacheRateProfiles } } } @@ -941,16 +912,10 @@ func (ldr *Loader) removeLoadedData(loaderType string, lds map[string][]LoaderDa return } case utils.MetaRemove: - for tntID := range lds { - if err = ldr.connMgr.Call(ldr.cacheConns, nil, - utils.CacheSv1RemoveItem, &utils.ArgsGetCacheItemWithOpts{ - ArgsGetCacheItem: utils.ArgsGetCacheItem{ - CacheID: cachePartition, - ItemID: tntID, - }, - }, &reply); err != nil { - return - } + if err = ldr.connMgr.Call(ldr.cacheConns, nil, + utils.CacheSv1RemoveItems, utils.AttrReloadCacheWithOpts{ + ArgsCache: cacheArgs}, &reply); err != nil { + return } case utils.MetaClear: if err = ldr.connMgr.Call(ldr.cacheConns, nil, diff --git a/utils/consts.go b/utils/consts.go index 6ddb56e25..b005a98b0 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -108,6 +108,20 @@ var ( CacheDispatcherFilterIndexes: DispatcherProfilePrefix, CacheRateProfilesFilterIndexes: RateProfilePrefix, CacheRateFilterIndexes: RatePrefix, + CacheReverseFilterIndexes: FilterPrefix, + } + + CacheInstanceToCacheIndex = map[string]string{ + CacheThresholdFilterIndexes: CacheThresholdProfiles, + CacheResourceFilterIndexes: CacheResourceProfiles, + CacheStatFilterIndexes: CacheStatQueueProfiles, + CacheRouteFilterIndexes: CacheRouteProfiles, + CacheAttributeFilterIndexes: CacheAttributeProfiles, + CacheChargerFilterIndexes: CacheChargerProfiles, + CacheDispatcherFilterIndexes: CacheDispatcherProfiles, + CacheRateProfilesFilterIndexes: CacheRateProfiles, + // CacheRateFilterIndexes: CacheRates, + CacheReverseFilterIndexes: CacheFilters, } // NonMonetaryBalances are types of balances which are not handled as monetary @@ -179,6 +193,7 @@ var ( RateFilterIndexIDs: RateFilterIndexPrfx, FilterIndexIDs: FilterIndexPrfx, } + CacheInstanceToArg map[string]string ArgCacheToInstance = map[string]string{ DestinationIDs: CacheDestinations, ReverseDestinationIDs: CacheReverseDestinations, @@ -1581,6 +1596,7 @@ const ( CacheSv1HasItem = "CacheSv1.HasItem" CacheSv1GetItemExpiryTime = "CacheSv1.GetItemExpiryTime" CacheSv1RemoveItem = "CacheSv1.RemoveItem" + CacheSv1RemoveItems = "CacheSv1.RemoveItems" CacheSv1PrecacheStatus = "CacheSv1.PrecacheStatus" CacheSv1HasGroup = "CacheSv1.HasGroup" CacheSv1GetGroupItemIDs = "CacheSv1.GetGroupItemIDs" @@ -2408,6 +2424,10 @@ func buildCacheInstRevPrefixes() { for k, v := range CacheInstanceToPrefix { CachePrefixToInstance[v] = k } + CacheInstanceToArg = make(map[string]string) + for k, v := range ArgCacheToInstance { + CacheInstanceToArg[v] = k + } } func init() {