Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

咨询一下动态修改配置的问题。 #1108

Open
Abbotton opened this issue Apr 21, 2022 · 0 comments
Open

咨询一下动态修改配置的问题。 #1108

Abbotton opened this issue Apr 21, 2022 · 0 comments

Comments

@Abbotton
Copy link

版本: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')方法确实可以得到修改后的配置值。

问题:
如何动态修改缓存配置并使其生效?

非常感谢。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant