-
Notifications
You must be signed in to change notification settings - Fork 77
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
[Feature] Cache settings #91
base: main
Are you sure you want to change the base?
Conversation
Add support to SettingsServiceProvider.php to cache settings using the Laravel cache. This slightly improves our performance.
BOOM! Your first PR with us, thank you so much! Someone will take a look at it shortly. Please keep in mind that:
Thank you! -- |
Satisfy style requirements.
Thank you for the PR @dkwiebe ! I agree - I see no reason why we shouldn't cache the settings, and prevent all those queries on page load. One thing popped up when looking over your PR (metioned it here too #90 (comment)): I think we also need to refresh the cache when a Setting is edited, so that the new value is instantly available. Otherwise I think the Admin will go edit a setting, see the new value in the admin panel, but not understand why that new value is not used on his website. Right? |
src/SettingsServiceProvider.php
Outdated
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 () { |
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 a settings.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.
src/SettingsServiceProvider.php
Outdated
|
||
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 () { |
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 have the same concern here - related to config('backpack.base.cache_time', 60)
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've adjusted this and updated the PR to merge with current code. I couldn't find a default cache time in Laravel and have added this setting in the backpack.settings file.
It's also been updated with the suggested code from here: #90 (comment)
Waiting this feature in new version! |
Add support to SettingsServiceProvider.php to cache settings using the Laravel cache. This slightly improves our performance by storing all the settings in whichever cache we use. For high traffic sites this saves a lot of database access.