cache method added

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