首页 > 解决方案 > 如何在 Laravel 7 中查看缓存记录?

问题描述

我有一堆来自使用 Laravel7 的老团队的代码。我有 2 个端点:

所以,我检查了相关代码:

资源/视图/电子邮件/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 相同吗?有没有办法检查缓存记录?我应该怎么做才能解决这个问题?

标签: cachinglaravel-7

解决方案


Cache::put('key', 'value', $seconds);
Cache::rememberForever('users', function () {
    return DB::table('users')->get();
}); 
Cache::get('key');
Cache::has('key');
Cache::pull('key');

推荐阅读