Skip to content
This repository was archived by the owner on Dec 6, 2019. It is now read-only.

Commit

Permalink
Fixes cache issue for POST requests
Browse files Browse the repository at this point in the history
  • Loading branch information
alecritson committed Dec 11, 2015
1 parent 67a2ca6 commit 8aa4835
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion placid/PlacidPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function getName()
}
function getVersion()
{
return '1.6.10';
return '1.6.16';
}
function getDeveloper()
{
Expand Down
9 changes: 9 additions & 0 deletions placid/manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
[
{
"version": "1.6.16",
"downloadUrl": "https://github.com/alecritson/Placid/archive/master.zip",
"date": "2015-12-11T00:00:00+00:00",
"notes": [
"# Bug Fixes",
"[Fixed] Fixed a bug where placid would return the wrong cached request for POST requests"
]
},
{
"version": "1.6.10",
"downloadUrl": "https://github.com/alecritson/Placid/archive/master.zip",
Expand Down
26 changes: 23 additions & 3 deletions placid/services/Placid_RequestsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ class Placid_RequestsService extends PlacidService
*/
protected $config;

/**
* The cache id of the request
* @var String
*/
protected $cacheId;

public function __construct()
{

Expand Down Expand Up @@ -90,8 +96,7 @@ public function request($handle = null, array $config = array())
}

// Get a cached request
$cachedRequest = craft()->placid_cache->get(base64_encode(urlencode($request->getUrl())));
$caches = craft()->placid_cache->get(base64_encode(urlencode($request->getUrl())));
$cachedRequest = craft()->placid_cache->get($this->_getCacheId());

// Import the onBeforeRequest event
Craft::import('plugins.placid.events.PlacidBeforeRequestEvent');
Expand Down Expand Up @@ -318,6 +323,8 @@ private function _createRequest($client, $record = null)
$this->config['url'] = $recordUrl;
}

$this->cacheId = $this->config['url'];

$request = $client->createRequest($this->config['method'], $this->config['url']);

if(array_key_exists('body', $this->config))
Expand Down Expand Up @@ -379,6 +386,11 @@ private function _createRequest($client, $record = null)
}
}

if($query)
{
$this->cacheId .= '?' . $query;
}

// Do we need to do some OAuth magic?
if($provider = $record->getAttribute('oauth'))
{
Expand Down Expand Up @@ -453,7 +465,7 @@ private function _getResponse(Client $client, $request)

if($this->config['cache'])
{
craft()->placid_cache->set($request->getUrl(), $output, $this->config['duration']);
craft()->placid_cache->set($this->_getCacheId(), $output, $this->config['duration']);
}

return $output;
Expand Down Expand Up @@ -523,4 +535,12 @@ private function _deleteWidgetsByRecord($id)
return true;
}

/**
* Returns the encoded cacheId for this request
* @return String The cache id
*/
private function _getCacheId()
{
return base64_encode(urlencode($this->cacheId));
}
}

0 comments on commit 8aa4835

Please sign in to comment.