• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang cache2go.GetCached函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/cgrates/cgrates/cache2go.GetCached函数的典型用法代码示例。如果您正苦于以下问题:Golang GetCached函数的具体用法?Golang GetCached怎么用?Golang GetCached使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了GetCached函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: GetAccAlias

func (ms *MapStorage) 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
		}
	}
	if values, ok := ms.dict[key]; ok {
		alias = string(values)
		cache2go.Cache(key, alias)
	} else {
		return "", errors.New(utils.ERR_NOT_FOUND)
	}
	return
}
开发者ID:intralanman,项目名称:cgrates,代码行数:17,代码来源:storage_map.go


示例17: GetActions

func (ms *MapStorage) 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
		}
	}
	if values, ok := ms.dict[key]; ok {
		err = ms.ms.Unmarshal(values, &as)
		cache2go.Cache(key, as)
	} else {
		return nil, errors.New(utils.ERR_NOT_FOUND)
	}
	return
}
开发者ID:intralanman,项目名称:cgrates,代码行数:17,代码来源:storage_map.go


示例18: GetLCR

func (ms *MapStorage) 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
		}
	}
	if values, ok := ms.dict[key]; ok {
		err = ms.ms.Unmarshal(values, &lcr)
		cache2go.Cache(key, lcr)
	} else {
		return nil, errors.New(utils.ERR_NOT_FOUND)
	}
	return
}
开发者ID:intralanman,项目名称:cgrates,代码行数:17,代码来源:storage_map.go


示例19: GetRatingProfile

func (rs *RedisStorage) GetRatingProfile(key string, skipCache bool) (rpf *RatingProfile, err error) {

	key = RATING_PROFILE_PREFIX + key
	if !skipCache {
		if x, err := cache2go.GetCached(key); err == nil {
			return x.(*RatingProfile), nil
		} else {
			return nil, err
		}
	}
	var values []byte
	if values, err = rs.db.Get(key); err == nil {
		rpf = new(RatingProfile)
		err = rs.ms.Unmarshal(values, rpf)
		cache2go.Cache(key, rpf)
	}
	return
}
开发者ID:intralanman,项目名称:cgrates,代码行数:18,代码来源:storage_redis.go


示例20: GetRatingProfile

func (ms *MapStorage) GetRatingProfile(key string, skipCache bool) (rpf *RatingProfile, err error) {
	key = RATING_PROFILE_PREFIX + key
	if !skipCache {
		if x, err := cache2go.GetCached(key); err == nil {
			return x.(*RatingProfile), nil
		} else {
			return nil, err
		}
	}
	if values, ok := ms.dict[key]; ok {
		rpf = new(RatingProfile)

		err = ms.ms.Unmarshal(values, rpf)
		cache2go.Cache(key, rpf)
	} else {
		return nil, errors.New(utils.ERR_NOT_FOUND)
	}
	return
}
开发者ID:intralanman,项目名称:cgrates,代码行数:19,代码来源:storage_map.go



注:本文中的github.com/cgrates/cgrates/cache2go.GetCached函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang cache2go.RemKey函数代码示例发布时间:2022-05-23
下一篇:
Golang cache2go.Get函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap