提问人:Ali Habieb 提问时间:8/25/2022 最后编辑:Ali Habieb 更新时间:8/26/2022 访问量:58
如何将新值推送到fat-free-framework中的缓存数组?
How to push a new value to a cached array in fat-free-framework?
问:
我有一个无脂肪框架应用程序,我需要缓存 API 调用,以便稍后将它们移动到 Cron 作业中的数据库:
<?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);
}
}
我使用 Redis 作为我的缓存驱动程序,并且新日志已成功推送到数组,但它似乎没有存储在缓存中,因为当我尝试在另一个请求中var_dump“API_CALLS”的内容时,它显示一个空数组
可能是什么问题?
答: 暂无答案
下一个:从 PUT 请求中获取数据
评论
!
f3->push
$hlr_item
BaseRepository::push
$hlr_item
$api_log
push
BaseRepository
set
$ttl
push
f3->set
f3->push