Skip to content
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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Conversation

dkwiebe
Copy link

@dkwiebe dkwiebe commented Dec 12, 2019

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.

Add support to SettingsServiceProvider.php to cache settings using the Laravel cache.  This slightly improves our performance.
@welcome
Copy link

welcome bot commented Dec 12, 2019

BOOM! Your first PR with us, thank you so much! Someone will take a look at it shortly.

Please keep in mind that:

  • if this constitutes a breaking change, it might take quite a while for this to get merged; we try to emulate the Laravel release cycle as much as possible, so developers can upgrade both software once; this means a new big release every ~6 months;
  • even if it's a non-breaking change, it might take a few days/weeks for the PR to get merged; unless it's a no-brainer, we like to have some community feedback on new features, before we merge them; this leads to higher-quality code, in the end; we learnt this the hard way :-)
  • not all PRs get merged; sometimes we just have to hold out new features, to keep the packages lean; sometimes we don't include features that only apply to niche use cases;
  • we're not perfect; if you think we're wrong, call us out on it; but in a kind way :-) we all make mistakes, best we learn from them and build better software together;

Thank you!

--
Justin Case
The Backpack Robot

Satisfy style requirements.
@tabacitu
Copy link
Member

tabacitu commented Dec 16, 2019

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?

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 () {
Copy link
Member

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 😄

Copy link
Author

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.


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 () {
Copy link
Member

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)

Copy link
Author

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)

@promatik promatik changed the title Update SettingsServiceProvider.php [Feature] Cache settings Sep 26, 2021
@marechenok
Copy link

Waiting this feature in new version!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants