How does config:cache work in laravel?
Do you like this post? Visiting yish.dev to get the latest post 🎉
We all know if you want to accelerate performance in laravel, you can do a lot of things, one of the things is cache what you think, likely route, config, view, etc, but how does it work in laravel?
To be noticed, cache DOES NOT cache your environment variables, there is documentation in official describe.
Caching And Env
If you are using the config:cache command during deployment, you must make sure that you are only calling the env function from within your configuration files, and not from anywhere else in your application.
If you are calling env from within your application, it is strongly recommended you add proper configuration values to your configuration files and call env from that location instead, allowing you to convert your env calls to config calls.
When you type
$ php artisan config:cache what happen to your application?
Calling your binding command class
Next, we explore the method
But here is a problem, the laravel how to know to load your configs cached or not?
And now we return back to see
getFreshConfiguration and you are seeing
For now, we all knew how does it work about config cache, at last, I found a tip about load bootstrap loading.
If you want to load the environment after bootstrapping, you can use