diff --git a/engine/caches.go b/engine/caches.go index 8948a7ebf..3a75efc6f 100644 --- a/engine/caches.go +++ b/engine/caches.go @@ -189,6 +189,10 @@ func (chS *CacheS) Clear(chIDs []string) { chS.tCache.Clear(chIDs) } +func (chS *CacheS) RemoveGroup(cacheID, groupID string) { + chS.tCache.RemoveGroup(cacheID, groupID, true, utils.NonTransactional) +} + // BeginTransaction is an exported method from TransCache func (chS *CacheS) BeginTransaction() string { return chS.tCache.BeginTransaction() diff --git a/engine/libindex.go b/engine/libindex.go index 914be9a82..8efdce5d7 100644 --- a/engine/libindex.go +++ b/engine/libindex.go @@ -398,8 +398,16 @@ func ComputeIndexes(dm *DataManager, tnt, ctx, idxItmType string, IDs *[]string, transactionID string, getFilters func(tnt, id, ctx string) (*[]string, error), newFltr *Filter) (indexes utils.StringSet, err error) { indexes = make(utils.StringSet) var profilesIDs []string + tntCtx := tnt + if ctx != utils.EmptyString { + tntCtx = utils.ConcatenatedKey(tnt, ctx) + } if IDs == nil { // get all items - Cache.Clear([]string{idxItmType}) + if ctx != utils.EmptyString { + Cache.RemoveGroup(idxItmType, tntCtx) + } else { + Cache.Clear([]string{idxItmType}) + } var ids []string if ids, err = dm.DataDB().GetKeysForPrefix(utils.CacheIndexesToPrefix[idxItmType]); err != nil { return @@ -410,10 +418,7 @@ func ComputeIndexes(dm *DataManager, tnt, ctx, idxItmType string, IDs *[]string, } else { profilesIDs = *IDs } - tntCtx := tnt - if ctx != utils.EmptyString { - tntCtx = utils.ConcatenatedKey(tnt, ctx) - } + // early lock to be sure that until we do not write back the indexes // another goroutine can't create new indexes refID := guardian.Guardian.GuardIDs(utils.EmptyString,