Work on config caching

This commit is contained in:
Graham Campbell 2016-01-30 12:03:28 +00:00
parent 7a3c231f68
commit 77f455651d

View File

@ -14,6 +14,8 @@ namespace CachetHQ\Cachet\Foundation\Providers;
use CachetHQ\Cachet\Config\Repository;
use CachetHQ\Cachet\Models\Setting as SettingModel;
use Exception;
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\ServiceProvider;
/**
@ -32,6 +34,20 @@ class ConfigServiceProvider extends ServiceProvider
*/
public function boot()
{
if ($this->app->configurationIsCached()) {
if ($this->app->environment() === 'production') {
$this->app->terminating(function () {
if ($this->app->setting->stale()) {
$this->app->make(Kernel::class)->call('config:cache');
}
});
} else {
$this->app->make(Kernel::class)->call('config:clear');
}
return;
}
try {
// Get the default settings.
$defaultSettings = $this->app->config->get('setting');
@ -72,6 +88,12 @@ class ConfigServiceProvider extends ServiceProvider
}
$this->app->config->set('cors.paths.api/v1/*.allowedOrigins', $allowedOrigins);
if ($this->app->environment() === 'production') {
$this->app->terminating(function () {
$this->app->make(Kernel::class)->call('config:cache');
});
}
}
/**