Пример #1
0
func CleanStalePrefixes(destIds []string) {
	prefixMap, err := cache2go.GetAllEntries(DESTINATION_PREFIX)
	if err != nil {
		return
	}
	for prefix, idIDs := range prefixMap {
		dIDs := idIDs.Value().([]interface{})
		changed := false
		for _, searchedDID := range destIds {
			if i, found := utils.GetSliceMemberIndex(utils.ConvertInterfaceSliceToStringSlice(dIDs), searchedDID); found {
				if len(dIDs) == 1 {
					// remove de prefix from cache
					cache2go.RemKey(DESTINATION_PREFIX + prefix)
				} else {
					// delte the testination from list and put the new list in chache
					dIDs[i], dIDs = dIDs[len(dIDs)-1], dIDs[:len(dIDs)-1]
					changed = true
				}
			}
		}
		if changed {
			cache2go.Cache(DESTINATION_PREFIX+prefix, dIDs)
		}
	}
}
Пример #2
0
func CleanStalePrefixes(destIds []string) {
	prefixMap, err := cache2go.GetAllEntries(utils.DESTINATION_PREFIX)
	if err != nil {
		return
	}
	for prefix, idIDs := range prefixMap {
		dIDs := idIDs.(map[interface{}]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)
				} else {
					// delete the destination from list and put the new list in chache
					delete(dIDs, searchedDID)
					changed = true
				}
			}
		}
		if changed {
			cache2go.Cache(utils.DESTINATION_PREFIX+prefix, dIDs)
		}
	}
}
Пример #3
0
func (rs *RedisStorage) GetAllActionPlans() (ats map[string]*ActionPlan, err error) {
	apls, err := cache2go.GetAllEntries(utils.ACTION_PLAN_PREFIX)
	if err != nil {
		return nil, err
	}

	ats = make(map[string]*ActionPlan, len(apls))
	for key, value := range apls {
		apl := value.(*ActionPlan)
		ats[key] = apl
	}

	return
}