-
Notifications
You must be signed in to change notification settings - Fork 80
[Feature] Cache settings #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
21d2f24
51fd1c4
962bf72
f6b10b5
37078a8
8fe6c14
367bf6c
7889f04
a0d513e
095d5d0
25cc3a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
use Backpack\Settings\app\Models\Setting as Setting; | ||
use Config; | ||
use Illuminate\Routing\Router; | ||
use Illuminate\Support\Facades\Cache; | ||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Support\ServiceProvider; | ||
use Route; | ||
|
@@ -36,9 +37,15 @@ public function boot() | |
$this->setupRoutes($this->app->router); | ||
|
||
// only use the Settings package if the Settings table is present in the database | ||
if (!\App::runningInConsole() && count(Schema::getColumnListing('settings'))) { | ||
// get all settings from the database | ||
$settings = Setting::all(); | ||
$tableExists = Cache::remember('backpack_settings_table_exists', config('backpack.base.cache_time', 60), function () { | ||
return count(Schema::getColumnListing('settings')); | ||
}); | ||
|
||
if (!\App::runningInConsole() && $tableExists) { | ||
// get all settings from the database if they're not in the database. | ||
$settings = Cache::remember('backpack_settings_cache', config('backpack.base.cache_time', 60), function () { | ||
|
||
return Setting::all(); | ||
}); | ||
|
||
// bind all settings to the Laravel config, so you can call them like | ||
// Config::get('settings.contact_email') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you've used
config('backpack.base.cache_time', 60)
. Is this a new config value you want to introduce? Since this is only used in Settings, I think it's better for it to be in asettings.php
config file, rather than Base.But I'm wondering - isn't it easier to just use the default cache time in the app? We're using the default cache store, so I think it's intuitive to use the default cache time too. Then we wouldn't need a
settings
config file at all 😄There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good points, I did add that in my instance but I'll patch it.