cache method added

This commit is contained in:
Olu Amey
2021-10-28 08:02:01 -04:00
parent 650d7c92b5
commit af11c58652
+22 -11
View File
@@ -8,18 +8,29 @@ class WpContentsClient
public static function serviceGetBlogItems($apiEndpointsUrl)
{
$client = new HTTPClient();
try {
$response = $client->request(
'GET',
"{$apiEndpointsUrl}/wordpress-data",
['connect_timeout' => 2, 'timeout' => 3, 'debug' => false]
);
} catch (Exception $e) {
// echo "\n".$e->getMessage()."\n";
$response= []; // empty array
$cache = \Config\Services::cache();
if (!$cache->get('BlogWebData')){
$client = new HTTPClient();
try {
$response = $client->request(
'GET',
"{$apiEndpointsUrl}/wordpress-data",
['connect_timeout' => 2, 'timeout' => 3, 'debug' => false]
);
} catch (Exception $e) {
// echo "\n".$e->getMessage()."\n";
$response= []; // empty array
}
$responseArray = json_decode($response->getBody());
$cache->save('BlogWebData',$responseArray,600);
}
return json_decode($response->getBody());
else{
$responseArray = $cache->get('BlogWebData');
}
//var_dump($responseArray);
return $responseArray;
}
}