mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Better cache key generation
All of the arguments supplied to the request function can impact what is returned by a restful service. This takes account of that and makes the cache key more specific, including basic auth details, so we don't rely on *just* the absolute URL for caching.
This commit is contained in:
parent
3457f43839
commit
7c189731e3
@ -115,7 +115,16 @@ class RestfulService extends ViewableData {
|
||||
assert(in_array($method, array('GET','POST','PUT','DELETE','HEAD','OPTIONS')));
|
||||
|
||||
$cachedir = TEMP_FOLDER; // Default silverstripe cache
|
||||
$cache_file = md5($url); // Encoded name of cache file
|
||||
//use var export on potentially nested arrays
|
||||
$cache_file_items = array(
|
||||
$subURL,
|
||||
$method,
|
||||
var_export($data, true),
|
||||
var_export(array_merge((array)$this->customHeaders, (array)$headers), true),
|
||||
var_export($curlOptions, true),
|
||||
"$this->authUsername:$this->authPassword"
|
||||
);
|
||||
$cache_file = md5(implode('-', $cache_file_items)); // Encoded name of cache file
|
||||
$cache_path = $cachedir."/xmlresponse_$cache_file";
|
||||
|
||||
// Check for unexpired cached feed (unless flush is set)
|
||||
@ -212,13 +221,6 @@ class RestfulService extends ViewableData {
|
||||
$responseBody = curl_exec($ch);
|
||||
$curlError = curl_error($ch);
|
||||
|
||||
// Problem verifying the server SSL certificate; just ignore it as it's not mandatory
|
||||
if(strpos($curlError,'14090086') !== false) {
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
$responseBody = curl_exec($ch);
|
||||
$curlError = curl_error($ch);
|
||||
}
|
||||
|
||||
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
if($curlError !== '' || $statusCode == 0) $statusCode = 500;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user