Laravel删除admin用户而不是标准用户的文件缓存



当用户登录并保持1分钟时,我存储在缓存中,当我登录/退出用户名为'user'它的工作,我可以访问缓存,但当我登录用户名为'admin'我访问他的缓存,但当他注销时,我得到这个错误:

<warning>PHP Warning:  fopen(/var/www/sitename/storage/framework/cache/data/16/6a/166a6e572c2df9368c554ead296c3ea04636d1d6): failed to open stream: No such file or directory in /var/www/sitename/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php on line 70</warning>

可能是因为用户名为"admin",自动认为这是一个"秘密"吗?无法打开的文件?

我使用tinker和cache::get()

恢复缓存。
Cache::get('user-is-online-52a1778c-c0d7-4de4-aa8b-a9a7931b5074')

Edit:用户注销后不删除缓存,而admin删除缓存文件…我不明白为什么

下面是存储缓存的代码:

if(Auth::check()) {
$expiresAt = Carbon::now()->addMinutes(1);
Cache::put('user-is-online-' . Auth::user()->id, true, $expiresAt);
}

首先检查键是否存在,以消除:get错误

if(Auth::check()) {
if (Cache::has('user-is-online-' . Auth::user()->id)) {
$my_cache= Cache::get('user-is-online-' . Auth::user()->id);
}
}

如何在注销时删除密钥?它是在注销之前还是之后出现?

对不起,我有一个特性,当模型上有交互时,它会被清楚地隐藏起来…


trait CacheClear
{
protected static function boot()
{
parent::boot();
/**
* After model is created, or whatever action, clear cache.
*/
static::updated(function () {
Cache::flush();
});
static::saved(function () {
Cache::flush();
});
static::deleted(function () {
Cache::flush();
});
}
}

最新更新