Permalink
Browse files

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.
  • Loading branch information...
1 parent 3457f43 commit 7c189731e332fc9b14be0e698c35c52cd868d938 @dhensby dhensby committed Jan 30, 2013
Showing with 10 additions and 8 deletions.
  1. +10 −8 api/RestfulService.php
View
@@ -115,7 +115,16 @@ public function request($subURL = '', $method = "GET", $data = null, $headers =
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 @@ public function curlRequest($url, $method, $data = null, $headers = null, $curlO
$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;

0 comments on commit 7c18973

Please sign in to comment.