Files
cgrates/config/cachecfg.go

128 lines
3.5 KiB
Go
Executable File

/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package config
import (
"time"
"github.com/cgrates/cgrates/utils"
"github.com/cgrates/ltcache"
)
type CacheParamCfg struct {
Limit int
TTL time.Duration
StaticTTL bool
Precache bool
}
func (self *CacheParamCfg) loadFromJsonCfg(jsnCfg *CacheParamJsonCfg) error {
if jsnCfg == nil {
return nil
}
var err error
if jsnCfg.Limit != nil {
self.Limit = *jsnCfg.Limit
}
if jsnCfg.Ttl != nil {
if self.TTL, err = utils.ParseDurationWithNanosecs(*jsnCfg.Ttl); err != nil {
return err
}
}
if jsnCfg.Static_ttl != nil {
self.StaticTTL = *jsnCfg.Static_ttl
}
if jsnCfg.Precache != nil {
self.Precache = *jsnCfg.Precache
}
return nil
}
type CacheCfg map[string]*CacheParamCfg
func (self CacheCfg) loadFromJsonCfg(jsnCfg *CacheJsonCfg) (err error) {
if jsnCfg == nil {
return
}
for kJsn, vJsn := range *jsnCfg {
val := new(CacheParamCfg)
if err := val.loadFromJsonCfg(vJsn); err != nil {
return err
}
self[kJsn] = val
}
return nil
}
func (cCfg CacheCfg) AsTransCacheConfig() (tcCfg map[string]*ltcache.CacheConfig) {
tcCfg = make(map[string]*ltcache.CacheConfig, len(cCfg))
for k, cPcfg := range cCfg {
tcCfg[k] = &ltcache.CacheConfig{
MaxItems: cPcfg.Limit,
TTL: cPcfg.TTL,
StaticTTL: cPcfg.StaticTTL,
}
}
return
}
// CGRATES_CFG_JSON_DISABLED_CACHE is used to populate cache config when DataDB is internal
const CGRATES_CFG_JSON_DISABLED_CACHE = `
{
"cache":{
"destinations": {"limit": 0},
"reverse_destinations": {"limit": 0},
"rating_plans": {"limit": 0},
"rating_profiles": {"limit": 0},
"actions": {"limit": 0},
"action_plans": {"limit": 0},
"account_action_plans": {"limit": 0},
"action_triggers": {"limit": 0},
"shared_groups": {"limit": 0},
"timings": {"limit": 0},
"resource_profiles": {"limit": 0},
"resources": {"limit": 0},
"event_resources": {"limit": 0},
"statqueue_profiles": {"limit": 0},
"statqueues": {"limit": 0},
"threshold_profiles": {"limit": 0},
"thresholds": {"limit": 0},
"filters": {"limit": 0},
"supplier_profiles": {"limit": 0},
"attribute_profiles": {"limit": 0},
"charger_profiles": {"limit": 0},
"dispatcher_profiles": {"limit": 0},
"dispatcher_hosts": {"limit": 0},
"resource_filter_indexes" : {"limit": 0},
"stat_filter_indexes" : {"limit": 0},
"threshold_filter_indexes" : {"limit": 0},
"supplier_filter_indexes" : {"limit": 0},
"attribute_filter_indexes" : {"limit": 0},
"charger_filter_indexes" : {"limit": 0},
"dispatcher_filter_indexes" : {"limit": 0},
"dispatcher_routes": {"limit": 0},
"diameter_messages": {"limit": -1, "ttl": "3h", "static_ttl": false}, // diameter messages caching
"rpc_responses": {"limit": 0, "ttl": "2s", "static_ttl": false}, // RPC responses caching
"closed_sessions": {"limit": -1, "ttl": "10s", "static_ttl": false}, // closed sessions cached for CDRs
"load_ids": {"limit": 0},
},
}`