本文整理汇总了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)
}
}
示例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
}
示例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
}
}
示例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
}
示例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
}
示例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)
}
示例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
}
示例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)
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}