public static function _read_unbounce_domain_info($options_getter, $options_setter, $fetch_proxyable_url_set, $domain, $expire_now = false) { $proxyable_url_set = null; $cache_max_time_default = 10; $ps_domain = $options_getter(UBConfig::UB_PAGE_SERVER_DOMAIN_KEY); $domains_info = $options_getter(UBConfig::UB_ROUTES_CACHE_KEY); $domain_info = UBUtil::array_fetch($domains_info, $domain, array()); $proxyable_url_set = UBUtil::array_fetch($domain_info, 'proxyable_url_set'); $proxyable_url_set_fetched_at = UBUtil::array_fetch($domain_info, 'proxyable_url_set_fetched_at'); $proxyable_url_set_cache_timeout = UBUtil::array_fetch($domain_info, 'proxyable_url_set_cache_timeout'); $proxyable_url_set_etag = UBUtil::array_fetch($domain_info, 'proxyable_url_set_etag'); $cache_max_time = is_null($proxyable_url_set_cache_timeout) ? $cache_max_time_default : $proxyable_url_set_cache_timeout; $current_time = time(); if ($expire_now || is_null($proxyable_url_set) || $current_time - $proxyable_url_set_fetched_at > $cache_max_time) { try { $can_fetch = UBUtil::get_lock(); UBLogger::debug('Locking: ' . $can_fetch); if ($can_fetch) { $result_array = call_user_func($fetch_proxyable_url_set, $domain, $proxyable_url_set_etag, $ps_domain); list($routes_status, $etag, $max_age, $proxyable_url_set_new) = $result_array; if ($routes_status['status'] == 'NEW') { $domain_info['proxyable_url_set'] = $proxyable_url_set_new; $domain_info['proxyable_url_set_etag'] = $etag; $domain_info['proxyable_url_set_cache_timeout'] = $max_age; } elseif ($routes_status['status'] == 'SAME') { // Just extend the cache $domain_info['proxyable_url_set_cache_timeout'] = $max_age; } elseif ($routes_status['status'] == 'NONE') { $domain_info['proxyable_url_set'] = array(); $domain_info['proxyable_url_set_etag'] = null; } elseif ($routes_status['status'] == 'FAILURE') { UBLogger::warning('Route fetching failed'); } else { UBLogger::warning("Unknown response from route fetcher: '{$routes_status}'"); } // Creation of domain_info entry $domain_info['proxyable_url_set_fetched_at'] = $current_time; $domain_info['last_status'] = $routes_status['status']; if ($routes_status['status'] == 'FAILURE') { $domain_info['failure_message'] = $routes_status['failure_message']; } $domains_info[$domain] = $domain_info; // set autoload to false so that options are always loaded from DB $options_setter(UBConfig::UB_ROUTES_CACHE_KEY, $domains_info, false); } } catch (Exception $e) { UBLogger::warning('Could not update sitemap: ' . $e); } $release_result = UBUtil::release_lock(); UBLogger::debug('Unlocking: ' . $release_result); } return UBUtil::array_select_by_key($domain_info, array('proxyable_url_set', 'proxyable_url_set_fetched_at', 'failure_message', 'last_status')); }