Skip to content

Commit

Permalink
Issue #8: improving the caching of SEO data, in case the API is often…
Browse files Browse the repository at this point in the history
… unreachable
  • Loading branch information
patrykkata committed Jan 27, 2017
1 parent 2504118 commit a976242
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions app/code/community/Styla/Connect/Model/Styla/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,28 @@ public function requestPageData($requestPath = '/')
*/
public function getPageSeoData($requestPath)
{
//check if a no-response status was cached
$seoRequest = $this->getRequest(self::REQUEST_TYPE_SEO)
->initialize($requestPath);

//if the result was already cached previously:
$cache = $this->getCache();
$cachedResponse = $cache->getCachedApiResponse($seoRequest);
if($cachedResponse) {
return $cachedResponse->getResult();
}

//otherwise, check if a no-response status was cached
if($cache->load('styla_seo_unreachable')) {
return array();
}

$seoRequest = $this->getRequest(self::REQUEST_TYPE_SEO)
->initialize($requestPath);

try {
$response = $this->callService($seoRequest);
$response = $this->callService($seoRequest, false); //do not use cache, we already checked it a moment ago

//if we had a success, store the retrieved values:
if ($response->getHttpStatus() === 200) {
$cache->storeApiResponse($seoRequest, $response);
}
} catch(Styla_Connect_Exception $e) {
//in case of the SEO request, we don't mind if the connection was failed. we'll just save this failed status for 5 minutes
//and not return anything.
Expand Down

0 comments on commit a976242

Please sign in to comment.