public static function HttpHelper::cachedRequest in Helper 7
2 calls to HttpHelper::cachedRequest()
- CacheHelper::httpRequest in lib/
CacheHelper.php - Deprecated.
- HttpHelper::getJson in lib/
HttpHelper.php
File
- lib/
HttpHelper.php, line 5
Class
Code
public static function cachedRequest($url, array $options = array(), $cache_errors = FALSE) {
$cid = static::cachedRequestGetCid($url, $options);
$bin = isset($options['cache']['bin']) ? $options['cache']['bin'] : 'cache';
if ($cid && ($cache = CacheHelper::get($cid, $bin))) {
return $cache->data;
}
else {
$response = drupal_http_request($url, $options);
$response->request_url = $url;
$response->request_options = $options;
if (!empty($response->error)) {
trigger_error("Error on request to {$url}: {$response->code} {$response->error}.", E_USER_WARNING);
}
if (!$cache_errors && !empty($response->error)) {
$cid = FALSE;
}
if ($cid) {
$expire = static::cachedRequestGetExpire($response, $options);
if ($expire !== FALSE) {
cache_set($cid, $response, $bin, $expire);
}
}
return $response;
}
}