mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-22 07:38:45 +05:00
added RemKey method for cache
This commit is contained in:
@@ -322,19 +322,18 @@ func (self *ApierV1) ReloadCache(attrs utils.ApiReloadCache, reply *string) erro
|
||||
if len(attrs.DestinationIds) > 0 {
|
||||
dstKeys = make([]string, len(attrs.DestinationIds))
|
||||
for idx, dId := range attrs.DestinationIds {
|
||||
dstKeys[idx] = engine.DESTINATION_PREFIX+dId // Cache expects them as redis keys
|
||||
dstKeys[idx] = engine.DESTINATION_PREFIX + dId // Cache expects them as redis keys
|
||||
}
|
||||
}
|
||||
if len(attrs.RatingPlanIds) > 0 {
|
||||
rpKeys = make([]string, len(attrs.RatingPlanIds))
|
||||
for idx, rpId := range attrs.RatingPlanIds {
|
||||
rpKeys[idx] = engine.RATING_PLAN_PREFIX+rpId
|
||||
rpKeys[idx] = engine.RATING_PLAN_PREFIX + rpId
|
||||
}
|
||||
}
|
||||
if err := self.DataDb.PreCache(dstKeys, rpKeys); err!= nil {
|
||||
if err := self.DataDb.PreCache(dstKeys, rpKeys); err != nil {
|
||||
return err
|
||||
}
|
||||
*reply = "OK"
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -104,6 +104,23 @@ func GetCached(key string) (v interface{}, err error) {
|
||||
return nil, errors.New("not found")
|
||||
}
|
||||
|
||||
func RemKey(key string) {
|
||||
mux.Lock()
|
||||
defer mux.Unlock()
|
||||
delete(cache, key)
|
||||
}
|
||||
|
||||
func XRemKey(key string) {
|
||||
mux.Lock()
|
||||
defer mux.Unlock()
|
||||
if r, ok := xcache[key]; ok {
|
||||
if r.timer() != nil {
|
||||
r.timer().Stop()
|
||||
}
|
||||
}
|
||||
delete(cache, key)
|
||||
}
|
||||
|
||||
// Delete all keys from expiraton cache
|
||||
func XFlush() {
|
||||
xMux.Lock()
|
||||
|
||||
@@ -63,7 +63,7 @@ Interface for storage providers.
|
||||
type DataStorage interface {
|
||||
Storage
|
||||
PreCache([]string, []string) error
|
||||
ExistsData(string, string)(bool, error)
|
||||
ExistsData(string, string) (bool, error)
|
||||
GetRatingPlan(string) (*RatingPlan, error)
|
||||
SetRatingPlan(*RatingPlan) error
|
||||
GetRatingProfile(string) (*RatingProfile, error)
|
||||
|
||||
@@ -21,6 +21,7 @@ package engine
|
||||
import (
|
||||
"bytes"
|
||||
"compress/zlib"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/cgrates/cgrates/cache2go"
|
||||
"github.com/cgrates/cgrates/history"
|
||||
@@ -30,7 +31,6 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type RedisStorage struct {
|
||||
@@ -88,7 +88,7 @@ func (rs *RedisStorage) PreCache(dKeys, rpKeys []string) (err error) {
|
||||
}
|
||||
}
|
||||
for _, key := range dKeys {
|
||||
// ToDo: cache2go.RemKey(key)
|
||||
cache2go.RemKey(key)
|
||||
if _, err = rs.GetDestination(key[len(DESTINATION_PREFIX):]); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -99,7 +99,7 @@ func (rs *RedisStorage) PreCache(dKeys, rpKeys []string) (err error) {
|
||||
}
|
||||
}
|
||||
for _, key := range rpKeys {
|
||||
// ToDo: cache2go.RemKey(key)
|
||||
cache2go.RemKey(key)
|
||||
if _, err = rs.GetRatingPlan(key[len(RATING_PLAN_PREFIX):]); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -110,15 +110,14 @@ func (rs *RedisStorage) PreCache(dKeys, rpKeys []string) (err error) {
|
||||
// Used to check if specific subject is stored using prefix key attached to entity
|
||||
func (rs *RedisStorage) ExistsData(entity, subject string) (bool, error) {
|
||||
switch entity {
|
||||
case DESTINATION_PREFIX:
|
||||
return rs.db.Exists(DESTINATION_PREFIX+subject)
|
||||
case DESTINATION_PREFIX:
|
||||
return rs.db.Exists(DESTINATION_PREFIX + subject)
|
||||
case RATING_PLAN_PREFIX:
|
||||
return rs.db.Exists(RATING_PLAN_PREFIX+subject)
|
||||
return rs.db.Exists(RATING_PLAN_PREFIX + subject)
|
||||
}
|
||||
return false, errors.New("Unsupported entity in ExistsData")
|
||||
}
|
||||
|
||||
|
||||
func (rs *RedisStorage) GetRatingPlan(key string) (rp *RatingPlan, err error) {
|
||||
if x, err := cache2go.GetCached(key); err == nil {
|
||||
return x.(*RatingPlan), nil
|
||||
|
||||
Reference in New Issue
Block a user