php - How to push a new value to a cached array in fat-free-framework?
one text
I have a fat-free-framework application where I need to cache API calls, in order to move them later to the database in a Cron job:
<?php
class ApiCallRepository extends BaseRepository
{
function __construct(ApiCall $model)
{
$this->f3 = Base::instance();
parent::__construct($model);
}
public function cache($url, $body, $response)
{
if(!$this->f3->exists('API_CALLS')) {
$this->f3->set('API_CALLS', [], 86400);
}
// die(var_export($this->f3->get("API_CALLS"), true));
/*
array (
)
*/
$createdAt = date("Y-m-d H:i:s");
$api_log = [
'url' => $url,
'body' => $body,
'response' => $response,
'createdAt' => $createdAt
];
$api_log = json_encode($api_log);
$this->f3->push("API_CALLS", $api_log);
die(var_export($this->f3->get("API_CALLS"), true));
/*
array (
0 =>
'{
"url":"https://api-resource.com/users",
"body":"",
"response":"{"data": {}}"
"createdAt":"2022-08-25 14:05:13"
}'
)
*/
}
public function create($url, $body, $response)
{
$this->model->create($url, $body, $response);
}
}
I am using Redis as my cache driver, and the new log is being pushed to the array successfully, but it doesn't seem to be stored in the cache, because when I try to var_dump the contents of 'API_CALLS' in a different request, it shows an empty array
what could be the problem?
Source