cache method added
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user