caching - 如何在 Laravel 7 中查看缓存记录?
问题描述
我有一堆来自使用 Laravel7 的老团队的代码。我有 2 个端点:
- wd/request-otp(工作,在我的测试电子邮件中收到 OTP)
- wdreq(总是说“你的 OTP 无效!”)
所以,我检查了相关代码:
资源/视图/电子邮件/otp.blade.php
<p>Your OTP:<p>
<p><h1>{{$otp}}</h1></p>
取款服务.php
/**
* @param $requestOTP
* @param $otpConfirmation
* @throws CustomException
*/
public function isValidOTP($requestOTP, $otpConfirmation)
{
if ($requestOTP !== (int) $otpConfirmation) {
throw new CustomException('Your OTP not valid', [$requestOTP, $otpConfirmation]);
}
}
OTP.php
/**
* Create OTP number and store in the cache
*
* @param string $prefix
* @param mixed $phone
* @return integer
*/
public function cacheTheOTP($prefix, $phone)
{
$OTP = rand(100000, 999999);
Cache::put([$this->OTPKey($prefix, $phone) => $OTP], \Carbon\Carbon::now()->addMinutes(10));
return $OTP;
}
也许 $requestOTP 总是 != $otpConfirmation (在我的电子邮件中收到,所以我可以看到它)。所以,我需要检查一下,$requestOTP 中的值是多少,与发送到我的电子邮件的 OTP 相同吗?有没有办法检查缓存记录?我应该怎么做才能解决这个问题?
解决方案
Cache::put('key', 'value', $seconds);
Cache::rememberForever('users', function () {
return DB::table('users')->get();
});
Cache::get('key');
Cache::has('key');
Cache::pull('key');
推荐阅读
- python-3.x - 格式化 Python 代码时撤消较短的行长
- npm - 当您无法推送到 master 时,使用 gitlab 发布新的节点包
- dictionary - Ansible:打印字典连接列表中的元素
- mysql - 在 EF Core 5.0 中使用 FromRawSql 会引发异常
- linux-kernel - 如何确定linux内核中NMI的来源?
- javascript - 如何使用 HTML 代码更改滑块拇指的可见性?
- excel - 将复杂字典保存到 Excel 文件中
- go - 如何从 Golang SDK 撤销 okta 令牌?
- rust - 参考宏中结构的泛型
- html - 如何显示具有不同类型 Y 轴值和相同 X 轴值的 React 多个折线图?