You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello everyone
I am opening this discussion to talk about an issue i found recently when programmatically changing default services like database connection or cache store
When changing Database default everything works superbly
now when trying to do the same for cache.store it failed
config('cache.default', 'STORE_A');
$store = app('cache.store'); // return STORE_A store
config('cache.default', 'STORE_B');
$store = app('cache.store'); // return STORE_A store
app()->forgetInstance('cache.store'); // <--- We need to forget the instance
$store = app('cache.store'); // return STORE_B store
And the reason is that 'db.connection' is not a singleton
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone
I am opening this discussion to talk about an issue i found recently when programmatically changing default services like database connection or cache store
When changing Database default everything works superbly
now when trying to do the same for cache.store it failed
And the reason is that 'db.connection' is not a singleton
https://github.com/laravel/framework/blob/8.x/src/Illuminate/Database/DatabaseServiceProvider.php#L71
whereas
cache.store
is.https://github.com/laravel/framework/blob/8.x/src/Illuminate/Cache/CacheServiceProvider.php#L22
Other "default" services are also set as singleton.
https://github.com/laravel/framework/blob/8.x/src/Illuminate/Filesystem/FilesystemServiceProvider.php#L42
So which way to do is correct ? why are they not defined the same way ? Is this a bug ? a feature request ?
my personal preference is to use bind as the actual service is actually "cached" in the managers (DatabaseManager / CacheManager)
Thank you
Beta Was this translation helpful? Give feedback.
All reactions