Adding SessionS.BiRPCv1SetPassiveSession RPC caching

This commit is contained in:
DanB
2019-03-03 20:40:48 +01:00
parent 28d4ac5c76
commit 7ea305f249
5 changed files with 25 additions and 5 deletions

View File

@@ -148,7 +148,7 @@ const CGRATES_CFG_JSON = `
"dispatcher_filter_indexes" : {"limit": -1, "ttl": "", "static_ttl": false}, // control dispatcher filter indexes caching
"dispatcher_routes": {"limit": -1, "ttl": "", "static_ttl": false}, // control dispatcher routes caching
"diameter_messages": {"limit": -1, "ttl": "3h", "static_ttl": false}, // diameter messages caching
"rpc_responses": {"limit": -1, "ttl": "2s", "static_ttl": false}, // RPC responses caching
"rpc_responses": {"limit": 0, "ttl": "2s", "static_ttl": false}, // RPC responses caching
},

View File

@@ -154,7 +154,7 @@ func TestCacheJsonCfg(t *testing.T) {
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false)},
utils.CacheDiameterMessages: &CacheParamJsonCfg{Limit: utils.IntPointer(-1),
Ttl: utils.StringPointer("3h"), Static_ttl: utils.BoolPointer(false)},
utils.CacheRPCResponses: &CacheParamJsonCfg{Limit: utils.IntPointer(-1),
utils.CacheRPCResponses: &CacheParamJsonCfg{Limit: utils.IntPointer(0),
Ttl: utils.StringPointer("2s"), Static_ttl: utils.BoolPointer(false)},
}

View File

@@ -705,7 +705,7 @@ func TestCgrCfgJSONDefaultsCacheCFG(t *testing.T) {
TTL: time.Duration(0), StaticTTL: false, Precache: false},
utils.CacheDiameterMessages: &CacheParamCfg{Limit: -1,
TTL: time.Duration(3 * time.Hour), StaticTTL: false},
utils.CacheRPCResponses: &CacheParamCfg{Limit: -1,
utils.CacheRPCResponses: &CacheParamCfg{Limit: 0,
TTL: time.Duration(2 * time.Second), StaticTTL: false},
}

View File

@@ -1383,7 +1383,7 @@ func (sS *SessionS) CallBiRPC(clnt rpcclient.RpcClientConnection,
// BiRPCv1GetActiveSessions returns the list of active sessions based on filter
func (sS *SessionS) BiRPCv1GetActiveSessions(clnt rpcclient.RpcClientConnection,
fltr map[string]string, reply *[]*ActiveSession) error {
fltr map[string]string, reply *[]*ActiveSession) (err error) {
for fldName, fldVal := range fltr {
if fldVal == "" {
fltr[fldName] = utils.META_NONE
@@ -1455,9 +1455,23 @@ func (sS *SessionS) BiRPCv1SetPassiveSession(clnt rpcclient.RpcClientConnection,
if s.CGRID == "" {
return utils.NewErrMandatoryIeMissing(utils.CGRID)
}
// handle RPC caching
cacheKey := utils.ConcatenatedKey("BiRPCv1SetPassiveSession", s.CGRID)
if itm, has := engine.Cache.Get(utils.CacheRPCResponses, cacheKey); has {
cachedResp := itm.(*utils.CachedRPCResponse)
if cachedResp.Error == nil {
*reply = *cachedResp.Result.(*string)
}
return cachedResp.Error
}
defer engine.Cache.Set(utils.CacheRPCResponses, cacheKey,
&utils.CachedRPCResponse{Result: reply, Error: err},
nil, true, utils.NonTransactional)
// end of RPC caching
if s.EventStart == nil { // remove instead of
if removed := sS.unregisterSession(s.CGRID, true); !removed {
return utils.ErrServerError
err = utils.ErrServerError
return
}
} else {
//if we have an active session with the same CGRID

View File

@@ -918,3 +918,9 @@ func (ffn *FallbackFileName) AsString() string {
}
return fmt.Sprintf("%s%s%s%s%s%s%s%s", ffn.Module, HandlerArgSep, ffn.Transport, HandlerArgSep, url.QueryEscape(ffn.Address), HandlerArgSep, ffn.RequestID, ffn.FileSuffix)
}
// CachedRPCResponse is used to cache a RPC response
type CachedRPCResponse struct {
Result interface{}
Error error
}