Strategy for caching config in multi-container deployed apps with blue green deployments? #55042
-
This issue #55028 gave us the idea of this question. Until now we did not found a perfect strategy in using cached configs. Reasons:
Based on this we evaluate caching the configs impossible in this scenario. Funny thing is that the community pays attention to the time gained by caching the configs but disregards the time lost by using reflection on each class that supports php attributes, even if they are not used and even suggesting octane as a solution. So, can anyone present e bulletproof solution for config caching in the above scenario? Update. config:cache merges all configs in 1 file and has nothing to do with Cache facade. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
This is your problem - the rest of the deployment process is designed to avoid config mis-matches and this roll-back is what breaks this process. |
Beta Was this translation helpful? Give feedback.
-
This sounds like you're sharing the result of |
Beta Was this translation helpful? Give feedback.
-
We noticed something when implementing config:cache and route:cache in lumen that is valid also for laravel 12. \Illuminate\Foundation\Application::normalizeCachePath protected function normalizeCachePath($key, $default)
{
if (is_null($env = Env::get($key))) {
return $this->bootstrapPath($default);
}
return Str::startsWith($env, $this->absoluteCachePathPrefixes)
? $env
: $this->basePath($env);
} The env is called multiple times and if the configs are cached it will return null making those APP_... envs useless. First we thought that config:cache should be called last but then we figured out that this is called on each request to check if there are cached files. This might be considered a bug but, because the config might not be loaded when this function is called, using something like: Env::get($key) ?? config('env.' . $key) will not work. |
Beta Was this translation helpful? Give feedback.
-
To answer the question what benefit can bring config and route caching we made a test. While calling last route out of more than 500 routes in a lumen project: $router->get('/jahdlkjdkjdlkw[/{id}]', [
'as' => 'version',
'uses' => 'VersionController@version',
]); No db calls involved just printing the version: public function version(): Response
{
return \response(\app()->version(), 200)
->header('Content-Type', 'text/html');
} 85-109 ms no config or route cache So 27-29% improvement. |
Beta Was this translation helpful? Give feedback.
The
config:cache
command generates a file atbootstrap/cache/config.php
, it doesn't use the framework's cache component at all. Caching the config (or any of the caches warmed up through theoptimize
command) has nothing to do with data cached using the Cache component, think of it more as a "cache this data that shouldn't change over the lifetime of a deployment" warmup step as you push a deployment live.Where this could cause problems is if you're caching the config at a point before the real values are set, i.e. something's being configured by an env var but those env vars aren't set in your build process; the
config:cache
command in Laravel is just a simplevar_export($config, true)
…