咨询一下动态修改配置的问题。
Abbotton opened this issue · 0 comments
Abbotton commented
版本:ThinkPHP v6.0.12
我定义了一个service
,在boot()
或者register()
方法中使用如下代码动态修改配置信息,会出现部分修改后的配置不生效的问题,代码如下:
public function boot()
{
// 修改文件系统配置
$filesystem = config('filesystem');
$filesystem['disks']['public']['url'] = '/storage/test';
$filesystem['disks']['public']['root'] = $this->app->getRootPath().'public'.DIRECTORY_SEPARATOR.'storage'.DIRECTORY_SEPARATOR.'test';
config(['filesystem' => $filesystem]);
// 修改缓存配置
$cache = config('cache');
$cache['stores']['file']['path'] = $this->app->getRuntimePath().'cache'.DIRECTORY_SEPARATOR.'test';
config(['cache' => $cache]);
}
经过测试:
修改了文件系统配置后,上传文件会存放到public/storage/test
目录中;
修改了缓存配置后,通过Cache::set()
方法设置缓存,缓存并没有存放到runtime/cache/test
目录中,但打印Cache::getConfig()
和Cache::getStoreConfig('file')
方法确实可以得到修改后的配置值。
问题:
如何动态修改缓存配置并使其生效?
非常感谢。