如何通过 Laravel 多租户使用文件缓存

How to use the file cache with Laravel Multi tenancy

我正在使用以下多租户包: https://laravel-tenancy.com/docs/hyn/5.3

Laravel: 5.7

我目前通过更改切换事件的配置让缓存租户知道。

Event::listen(Switched::class, function (Switched $event) {
   config(['cache.stores.file.path' => storage_path('framework/cache/' . $event->website->uuid)]);
});

这在执行如下命令时效果很好:

php artisan tenancy:run my:caching-command --tenant=2

效果不佳:

php artisan tenancy:run my:caching-command

在这种情况下,只为第一个租户创建缓存目录。调试时,我发现配置实际上已针对每个租户正确更新。但是缓存驱动程序没有使用新路径...

有人有什么想法吗?

我需要重建缓存实例:

app()->forgetInstance('cache');

如果稍后在您的代码中通过 app('cache') 访问缓存实例,它将使用您当前的配置重建。