Ferid's avatar

Config cache ignore

I need to ignore caching for specific custom config file in laravel /config/* directory

0 likes
7 replies
LaryAI's avatar

Laravel’s config caching (php artisan config:cache) compiles all configuration files in the /config directory into a single cache file. There is no built-in way to exclude specific config files from this process. All files in /config are included.

Workarounds:

  1. Move the Config File Outside /config:
    If you don’t want a file cached, move it outside /config (e.g., /storage or elsewhere). Then, load it manually when needed:

    $customConfig = require base_path('path/to/your/custom.php');
    
  2. Load Dynamically (Not via config()):
    Don’t use config('custom') for this file. Instead, load it as shown above, so it’s not part of the config cache.

  3. Environment Variables:
    If the data is simple, consider using .env variables instead.

Summary:
You cannot tell Laravel to ignore a specific file in /config during config caching. The only way is to keep that file outside /config and load it manually.

References:

JussiMannisto's avatar

You don't do that. When Laravel constructs the config object, it either reads from the individual config files or from the cache. Doing both would negate any benefits gained from caching.

What problem are you trying to solve?

martinbean's avatar

@ferid The entire point of the config:cache command is to, well, cache configuration values. So why would you intentionally want to break that behaviour?

Glukinho's avatar

To have ability to set configs dynamically, maybe by a customer?

JussiMannisto's avatar

@Glukinho Configuration files are part of the source code and shouldn't change during runtime, much less environment variables. Dynamic settings should be maintained somewhere else.

Ferid's avatar
Ferid
OP
Best Answer
Level 6

I got I was wrong with this idea. So I had admin configuration file and in that static array I had callbacks that is why couldn't cache that file properly. So I decide to move that config to app/service

Please or to participate in this conversation.