mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added RPC caching Responder.GetCost
This commit is contained in:
committed by
Dan Christian Bogos
parent
df2fff3952
commit
350224ad2b
@@ -58,6 +58,25 @@ func (rs *Responder) usageAllowed(tor string, reqUsage time.Duration) (allowed b
|
||||
RPC method thet provides the external RPC interface for getting the rating information.
|
||||
*/
|
||||
func (rs *Responder) GetCost(arg *CallDescriptorWithArgDispatcher, reply *CallCost) (err error) {
|
||||
// RPC caching
|
||||
if config.CgrConfig().CacheCfg()[utils.CacheRPCResponses].Limit != 0 {
|
||||
cacheKey := utils.ConcatenatedKey(utils.ResponderGetCost, arg.CgrID)
|
||||
refID := guardian.Guardian.GuardIDs("",
|
||||
config.CgrConfig().GeneralCfg().LockingTimeout, cacheKey) // RPC caching needs to be atomic
|
||||
defer guardian.Guardian.UnguardIDs(refID)
|
||||
|
||||
if itm, has := Cache.Get(utils.CacheRPCResponses, cacheKey); has {
|
||||
cachedResp := itm.(*utils.CachedRPCResponse)
|
||||
if cachedResp.Error == nil {
|
||||
*reply = *cachedResp.Result.(*CallCost)
|
||||
}
|
||||
return cachedResp.Error
|
||||
}
|
||||
defer Cache.Set(utils.CacheRPCResponses, cacheKey,
|
||||
&utils.CachedRPCResponse{Result: reply, Error: err},
|
||||
nil, true, utils.NonTransactional)
|
||||
}
|
||||
// end of RPC caching
|
||||
if arg.Tenant == "" {
|
||||
arg.Tenant = config.CgrConfig().GeneralCfg().DefaultTenant
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user