static void fill_cache(cps_api_key_t *key,const cps_api_object_owner_reg_t &owner) { std_mutex_simple_lock_guard lg(&cache_lock); _cache.erase(key); cache_entry ce ; ce.owner = owner; ce.last_updated = std_get_uptime(nullptr); _cache.insert(key,ce); }
static bool load_groups() { std::lock_guard<std::recursive_mutex> lg(_mutex); if (std_time_is_expired(_last_loaded,5*1000*1000)) { _last_loaded = std_get_uptime(nullptr); return _nodes->load(); } return false; }
static bool cache_connect(cps_api_key_t &key, cps_api_channel_t &handle) { std_mutex_simple_lock_guard lg(&cache_lock); cache_entry ce; if (_cache.find(&key,ce,true)) { const static int TM = MILLI_TO_MICRO(1000) * 20; //20 seconds bool expired = (std_get_uptime(nullptr) - ce.last_updated) > TM; if (!expired && (cps_api_connect_owner(&ce.owner, handle)==cps_api_ret_code_OK)) { return true; } else { char buff[SCRATCH_LOG_BUFF]; EV_LOG(TRACE,DSAPI,0,"CPS-NS-CACHE","cache expired for key:%s", cps_api_key_print(&key,buff,sizeof(buff))); _cache.erase(&key); } } return false; }