cache method added
This commit is contained in:
@@ -8,18 +8,29 @@ class WpContentsClient
|
|||||||
|
|
||||||
public static function serviceGetBlogItems($apiEndpointsUrl)
|
public static function serviceGetBlogItems($apiEndpointsUrl)
|
||||||
{
|
{
|
||||||
$client = new HTTPClient();
|
$cache = \Config\Services::cache();
|
||||||
try {
|
|
||||||
$response = $client->request(
|
if (!$cache->get('BlogWebData')){
|
||||||
'GET',
|
$client = new HTTPClient();
|
||||||
"{$apiEndpointsUrl}/wordpress-data",
|
|
||||||
['connect_timeout' => 2, 'timeout' => 3, 'debug' => false]
|
try {
|
||||||
);
|
$response = $client->request(
|
||||||
} catch (Exception $e) {
|
'GET',
|
||||||
// echo "\n".$e->getMessage()."\n";
|
"{$apiEndpointsUrl}/wordpress-data",
|
||||||
$response= []; // empty array
|
['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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user