我正在使用 laravel 和 Redis 驱动程序来存储我的缓存,并将我的 key 范围限制为当前租户。以下是我设置缓存的方法;其中 $tenant
是当前租户。
$department_count = Cache::remember('dep_count:'.$tenant, 60 * 60 * 24, function () use ($tenant) {
return Department::where('is_active', 'yes')->where('tenantID', $tenant)->count();
});
因此,在转校时,我想使用 cache::forget()
清除当前租户的所有缓存,但我不知道该怎么做。
我尝试过Cache::forget('*:'.$tenant)
但它似乎不起作用。非常感谢任何有关如何进行的帮助。
最佳答案
如果您想要组缓存并仅删除特定的缓存组,您可以使用标签。
请阅读this 。会有帮助的
Cache::tags(['tag_'.$tenant])->remember('dep_count:'.$tenant, 60 * 60 * 24, function () use ($tenant) {
return Department::where('is_active', 'yes')->where('tenantID', $tenant)->count();
});
用于删除
Cache::tags(['tag_'.$tenant])->flush();
关于laravel - 使用正则表达式忘记缓存 laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73002672/