From 7c189731e332fc9b14be0e698c35c52cd868d938 Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Wed, 30 Jan 2013 16:39:18 +0000 Subject: [PATCH] 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. --- api/RestfulService.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/api/RestfulService.php b/api/RestfulService.php index 8a333afec..bd332dbfa 100644 --- a/api/RestfulService.php +++ b/api/RestfulService.php @@ -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;