[英]How to use the file cache with Laravel Multi tenancy
I'm using the following multi tenancy package: https://laravel-tenancy.com/docs/hyn/5.3 我正在使用以下多租户套餐: https : //laravel-tenancy.com/docs/hyn/5.3
Laravel: 5.7 Laravel:5.7
I current made the caching tenant aware by changing the config on the switched event. 我当前通过更改切换事件的配置来了解缓存租户。
Event::listen(Switched::class, function (Switched $event) {
config(['cache.stores.file.path' => storage_path('framework/cache/' . $event->website->uuid)]);
});
This works well when doing a command like: 这在执行如下命令时效果很好:
php artisan tenancy:run my:caching-command --tenant=2
This does not work well: 这不行:
php artisan tenancy:run my:caching-command
In this case only a cache dir is created for the first tenant. 在这种情况下,仅为第一个租户创建缓存目录。 When debugging it, I found that the config is actually properly updated for each tenant.
调试时,我发现配置实际上已为每个租户正确更新。 However the cache driver is not using the new path...
但是缓存驱动程序没有使用新路径...
Anyone any ideas? 任何想法?
I needed to rebuild the cache instance with: 我需要重建缓存实例:
app()->forgetInstance('cache');
If lateron in your code the cache instance is accessed via app('cache')
, it will be rebuild with your current config. 如果在代码中稍后通过
app('cache')
访问缓存实例,它将使用您当前的配置进行重建。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.