當前位置: 首頁>>代碼示例>>Golang>>正文


Golang cache2go.GetCached函數代碼示例

本文整理匯總了Golang中github.com/cgrates/cgrates/cache2go.GetCached函數的典型用法代碼示例。如果您正苦於以下問題:Golang GetCached函數的具體用法?Golang GetCached怎麽用?Golang GetCached使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了GetCached函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestCleanStalePrefixes

func TestCleanStalePrefixes(t *testing.T) {
	cache2go.Cache(DESTINATION_PREFIX+"1", []interface{}{"D1", "D2"})
	cache2go.Cache(DESTINATION_PREFIX+"2", []interface{}{"D1"})
	cache2go.Cache(DESTINATION_PREFIX+"3", []interface{}{"D2"})
	CleanStalePrefixes([]string{"D1"})
	if r, err := cache2go.GetCached(DESTINATION_PREFIX + "1"); err != nil || len(r.([]interface{})) != 1 {
		t.Error("Error cleaning stale destination ids", r)
	}
	if r, err := cache2go.GetCached(DESTINATION_PREFIX + "2"); err == nil {
		t.Error("Error removing stale prefix: ", r)
	}
	if r, err := cache2go.GetCached(DESTINATION_PREFIX + "3"); err != nil || len(r.([]interface{})) != 1 {
		t.Error("Error performing stale cleaning: ", r)
	}
}
開發者ID:intralanman,項目名稱:cgrates,代碼行數:15,代碼來源:destinations_test.go

示例2: GetRatingPlan

func (rs *RedisStorage) GetRatingPlan(key string, skipCache bool) (rp *RatingPlan, err error) {
	key = RATING_PLAN_PREFIX + key
	if !skipCache {
		if x, err := cache2go.GetCached(key); err == nil {
			return x.(*RatingPlan), nil
		} else {
			return nil, err
		}
	}
	var values []byte
	if values, err = rs.db.Get(key); err == nil {
		b := bytes.NewBuffer(values)
		r, err := zlib.NewReader(b)
		if err != nil {
			return nil, err
		}
		out, err := ioutil.ReadAll(r)
		if err != nil {
			return nil, err
		}
		r.Close()
		rp = new(RatingPlan)
		err = rs.ms.Unmarshal(out, rp)
		cache2go.Cache(key, rp)
	}
	return
}
開發者ID:intralanman,項目名稱:cgrates,代碼行數:27,代碼來源:storage_redis.go

示例3: addUnits

// Adds the units from the received balance to an existing balance if the destination
// is the same or ads the balance to the list if none matches.
func (uc *UnitsCounter) addUnits(amount float64, prefix string) {
	counted := false
	if prefix != "" {
		for _, mb := range uc.Balances {
			if !mb.HasDestination() {
				continue
			}
			for _, p := range utils.SplitPrefix(prefix, MIN_PREFIX_MATCH) {
				if x, err := cache2go.GetCached(DESTINATION_PREFIX + p); err == nil {
					destIds := x.([]interface{})
					for _, dId := range destIds {
						if dId == mb.DestinationId {
							mb.Value += amount
							counted = true
							break
						}
					}
				}
				if counted {
					break
				}
			}
		}
	}
	if !counted {
		// use general balance
		b := uc.GetGeneralBalance()
		b.Value += amount
	}
}
開發者ID:intralanman,項目名稱:cgrates,代碼行數:32,代碼來源:units_counter.go

示例4: GetLCREntryForPrefix

func (lcra *LCRActivation) GetLCREntryForPrefix(destination string) *LCREntry {
	var potentials LCREntriesSorter
	for _, p := range utils.SplitPrefix(destination, MIN_PREFIX_MATCH) {
		if x, err := cache2go.GetCached(DESTINATION_PREFIX + p); err == nil {
			destIds := x.([]string)
			for _, dId := range destIds {
				for _, entry := range lcra.Entries {
					if entry.DestinationId == dId {
						entry.precision = len(p)
						potentials = append(potentials, entry)
					}
				}
			}
		}
	}
	if len(potentials) > 0 {
		// sort by precision and weight
		potentials.Sort()
		return potentials[0]
	}
	// return the *any entry if it exists
	for _, entry := range lcra.Entries {
		if entry.DestinationId == utils.ANY {
			return entry
		}
	}
	return nil
}
開發者ID:intralanman,項目名稱:cgrates,代碼行數:28,代碼來源:lcr.go

示例5: GetRatingPlan

func (ms *MapStorage) GetRatingPlan(key string, skipCache bool) (rp *RatingPlan, err error) {
	key = RATING_PLAN_PREFIX + key
	if !skipCache {
		if x, err := cache2go.GetCached(key); err == nil {
			return x.(*RatingPlan), nil
		} else {
			return nil, err
		}
	}
	if values, ok := ms.dict[key]; ok {
		b := bytes.NewBuffer(values)
		r, err := zlib.NewReader(b)
		if err != nil {
			return nil, err
		}
		out, err := ioutil.ReadAll(r)
		if err != nil {
			return nil, err
		}
		r.Close()
		rp = new(RatingPlan)
		err = ms.ms.Unmarshal(out, rp)
		cache2go.Cache(key, rp)
	} else {
		return nil, errors.New(utils.ERR_NOT_FOUND)
	}
	return
}
開發者ID:intralanman,項目名稱:cgrates,代碼行數:28,代碼來源:storage_map.go

示例6: GetKey

// Constructs the key for the storage lookup.
// The prefixLen is limiting the length of the destination prefix.
func (cd *CallDescriptor) GetKey(subject string) string {
	// check if subject is alias
	if rs, err := cache2go.GetCached(RP_ALIAS_PREFIX + utils.RatingSubjectAliasKey(cd.Tenant, subject)); err == nil {
		realSubject := rs.(string)
		subject = realSubject
		cd.Subject = realSubject
	}
	return fmt.Sprintf("%s:%s:%s:%s", cd.Direction, cd.Tenant, cd.Category, subject)
}
開發者ID:intralanman,項目名稱:cgrates,代碼行數:11,代碼來源:calldesc.go

示例7: CachedDestHasPrefix

// Reverse search in cache to see if prefix belongs to destination id
func CachedDestHasPrefix(destId, prefix string) bool {
	if cached, err := cache2go.GetCached(DESTINATION_PREFIX + prefix); err == nil {
		for _, cachedDstId := range cached.([]interface{}) {
			if destId == cachedDstId {
				return true
			}
		}
	}
	return false
}
開發者ID:intralanman,項目名稱:cgrates,代碼行數:11,代碼來源:destinations.go

示例8: GetAccountKey

// Returns the key used to retrive the user balance involved in this call
func (cd *CallDescriptor) GetAccountKey() string {
	subj := cd.Subject
	if cd.Account != "" {
		// check if subject is alias
		if realSubject, err := cache2go.GetCached(ACC_ALIAS_PREFIX + utils.AccountAliasKey(cd.Tenant, subj)); err == nil {
			cd.Account = realSubject.(string)
		}
		subj = cd.Account
	}
	return fmt.Sprintf("%s:%s:%s", cd.Direction, cd.Tenant, subj)
}
開發者ID:intralanman,項目名稱:cgrates,代碼行數:12,代碼來源:calldesc.go

示例9: GetDerivedChargers

func (rs *RedisStorage) GetDerivedChargers(key string, skipCache bool) (dcs utils.DerivedChargers, err error) {
	key = DERIVEDCHARGERS_PREFIX + key
	if !skipCache {
		if x, err := cache2go.GetCached(key); err == nil {
			return x.(utils.DerivedChargers), nil
		} else {
			return nil, err
		}
	}
	var values []byte
	if values, err = rs.db.Get(key); err == nil {
		err = rs.ms.Unmarshal(values, &dcs)
		cache2go.Cache(key, dcs)
	}
	return dcs, err
}
開發者ID:intralanman,項目名稱:cgrates,代碼行數:16,代碼來源:storage_redis.go

示例10: GetSharedGroup

func (rs *RedisStorage) GetSharedGroup(key string, skipCache bool) (sg *SharedGroup, err error) {
	key = SHARED_GROUP_PREFIX + key
	if !skipCache {
		if x, err := cache2go.GetCached(key); err == nil {
			return x.(*SharedGroup), nil
		} else {
			return nil, err
		}
	}
	var values []byte
	if values, err = rs.db.Get(key); err == nil {
		err = rs.ms.Unmarshal(values, &sg)
		cache2go.Cache(key, sg)
	}
	return
}
開發者ID:intralanman,項目名稱:cgrates,代碼行數:16,代碼來源:storage_redis.go

示例11: GetActions

func (rs *RedisStorage) GetActions(key string, skipCache bool) (as Actions, err error) {
	key = ACTION_PREFIX + key
	if !skipCache {
		if x, err := cache2go.GetCached(key); err == nil {
			return x.(Actions), nil
		} else {
			return nil, err
		}
	}
	var values []byte
	if values, err = rs.db.Get(key); err == nil {
		err = rs.ms.Unmarshal(values, &as)
		cache2go.Cache(key, as)
	}
	return
}
開發者ID:intralanman,項目名稱:cgrates,代碼行數:16,代碼來源:storage_redis.go

示例12: GetAccAlias

func (rs *RedisStorage) GetAccAlias(key string, skipCache bool) (alias string, err error) {
	key = ACC_ALIAS_PREFIX + key
	if !skipCache {
		if x, err := cache2go.GetCached(key); err == nil {
			return x.(string), nil
		} else {
			return "", err
		}
	}
	var values []byte
	if values, err = rs.db.Get(key); err == nil {
		alias = string(values)
		cache2go.Cache(key, alias)
	}
	return
}
開發者ID:intralanman,項目名稱:cgrates,代碼行數:16,代碼來源:storage_redis.go

示例13: GetLCR

func (rs *RedisStorage) GetLCR(key string, skipCache bool) (lcr *LCR, err error) {
	key = LCR_PREFIX + key
	if !skipCache {
		if x, err := cache2go.GetCached(key); err == nil {
			return x.(*LCR), nil
		} else {
			return nil, err
		}
	}
	var values []byte
	if values, err = rs.db.Get(key); err == nil {
		err = rs.ms.Unmarshal(values, &lcr)
		cache2go.Cache(key, lcr)
	}
	return
}
開發者ID:intralanman,項目名稱:cgrates,代碼行數:16,代碼來源:storage_redis.go

示例14: GetDerivedChargers

func (ms *MapStorage) GetDerivedChargers(key string, skipCache bool) (dcs utils.DerivedChargers, err error) {
	key = DERIVEDCHARGERS_PREFIX + key
	if !skipCache {
		if x, err := cache2go.GetCached(key); err == nil {
			return x.(utils.DerivedChargers), nil
		} else {
			return nil, err
		}
	}
	if values, ok := ms.dict[key]; ok {
		err = ms.ms.Unmarshal(values, &dcs)
		cache2go.Cache(key, dcs)
	} else {
		return nil, errors.New(utils.ERR_NOT_FOUND)
	}
	return
}
開發者ID:intralanman,項目名稱:cgrates,代碼行數:17,代碼來源:storage_map.go

示例15: GetSharedGroup

func (ms *MapStorage) GetSharedGroup(key string, skipCache bool) (sg *SharedGroup, err error) {
	key = SHARED_GROUP_PREFIX + key
	if !skipCache {
		if x, err := cache2go.GetCached(key); err == nil {
			return x.(*SharedGroup), nil
		} else {
			return nil, err
		}
	}
	if values, ok := ms.dict[key]; ok {
		err = ms.ms.Unmarshal(values, &sg)
		cache2go.Cache(key, sg)
	} else {
		return nil, errors.New(utils.ERR_NOT_FOUND)
	}
	return
}
開發者ID:intralanman,項目名稱:cgrates,代碼行數:17,代碼來源:storage_map.go


注:本文中的github.com/cgrates/cgrates/cache2go.GetCached函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。