From 21d2f241161ff02ea82923a5399234420f17772d Mon Sep 17 00:00:00 2001 From: Darren Wiebe Date: Mon, 25 Nov 2019 22:03:42 -0700 Subject: [PATCH 1/9] Update SettingsServiceProvider.php Add support to SettingsServiceProvider.php to cache settings using the Laravel cache. This slightly improves our performance. --- src/SettingsServiceProvider.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/SettingsServiceProvider.php b/src/SettingsServiceProvider.php index aca4c9d..2bbb374 100644 --- a/src/SettingsServiceProvider.php +++ b/src/SettingsServiceProvider.php @@ -6,6 +6,7 @@ use Config; use Illuminate\Routing\Router; use Illuminate\Support\Facades\Schema; +use Illuminate\Support\Facades\Cache; 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') From 51fd1c42f2a5c48a6b4d65f1935a0d5455dfa817 Mon Sep 17 00:00:00 2001 From: Darren Wiebe Date: Wed, 11 Dec 2019 23:02:56 -0700 Subject: [PATCH 2/9] Update SettingsServiceProvider.php Satisfy style requirements. --- src/SettingsServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SettingsServiceProvider.php b/src/SettingsServiceProvider.php index 2bbb374..c1e6f4d 100644 --- a/src/SettingsServiceProvider.php +++ b/src/SettingsServiceProvider.php @@ -5,8 +5,8 @@ use Backpack\Settings\app\Models\Setting as Setting; use Config; use Illuminate\Routing\Router; -use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\Schema; use Illuminate\Support\ServiceProvider; use Route; From 962bf728e5ad20f45b580106b8a95dc4f89a3829 Mon Sep 17 00:00:00 2001 From: dkwiebe Date: Thu, 30 Jun 2022 19:17:06 -0600 Subject: [PATCH 3/9] Revert "Update SettingsServiceProvider.php" This reverts commit 51fd1c42f2a5c48a6b4d65f1935a0d5455dfa817. --- src/SettingsServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SettingsServiceProvider.php b/src/SettingsServiceProvider.php index c1e6f4d..2bbb374 100644 --- a/src/SettingsServiceProvider.php +++ b/src/SettingsServiceProvider.php @@ -5,8 +5,8 @@ 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\Facades\Cache; use Illuminate\Support\ServiceProvider; use Route; From f6b10b572fdcae1997d83119925ca53745f19e02 Mon Sep 17 00:00:00 2001 From: dkwiebe Date: Thu, 30 Jun 2022 19:17:10 -0600 Subject: [PATCH 4/9] Revert "Update SettingsServiceProvider.php" This reverts commit 21d2f241161ff02ea82923a5399234420f17772d. --- src/SettingsServiceProvider.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/SettingsServiceProvider.php b/src/SettingsServiceProvider.php index 2bbb374..aca4c9d 100644 --- a/src/SettingsServiceProvider.php +++ b/src/SettingsServiceProvider.php @@ -6,7 +6,6 @@ use Config; use Illuminate\Routing\Router; use Illuminate\Support\Facades\Schema; -use Illuminate\Support\Facades\Cache; use Illuminate\Support\ServiceProvider; use Route; @@ -37,15 +36,9 @@ public function boot() $this->setupRoutes($this->app->router); // only use the Settings package if the Settings table is present in the database - $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(); - }); + if (!\App::runningInConsole() && count(Schema::getColumnListing('settings'))) { + // get all settings from the database + $settings = Setting::all(); // bind all settings to the Laravel config, so you can call them like // Config::get('settings.contact_email') From 8fe6c14cbc2dd8d4c1a20bcd719e8532c7dd1e2a Mon Sep 17 00:00:00 2001 From: dkwiebe Date: Thu, 30 Jun 2022 19:40:00 -0600 Subject: [PATCH 5/9] Add support to cache all database settings --- src/SettingsServiceProvider.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/SettingsServiceProvider.php b/src/SettingsServiceProvider.php index 70413e4..900a60d 100644 --- a/src/SettingsServiceProvider.php +++ b/src/SettingsServiceProvider.php @@ -5,6 +5,7 @@ use Backpack\Settings\app\Models\Setting; use Config; use Illuminate\Routing\Router; +use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Schema; use Illuminate\Support\ServiceProvider; use Route; @@ -41,10 +42,21 @@ public function boot() // define the routes for the application $this->setupRoutes($this->app->router); + // listen for settings to be saved and clear the cache when any Setting model is saved. + Setting::saved(function () { + Cache::forget('backpack_settings_cache'); + }); + // only use the Settings package if the Settings table is present in the database - if (!\App::runningInConsole() && Schema::hasTable(config('backpack.settings.table_name'))) { - // get all settings from the database - $settings = Setting::all(); + $tableExists = Cache::remember('backpack_settings_table_exists', config('backpack.settings.cache_time', 60), function () { + return Schema::hasTable(config('backpack.settings.table_name')); + }); + + if (!\App::runningInConsole() && $tableExists) { + // get all settings from the database if they're not in the database. + $settings = Cache::rememberForever('backpack_settings_cache', config('backpack.settings.cache_time', 60), function () { + return Setting::all(); + }); $config_prefix = config('backpack.settings.config_prefix'); From 367bf6c40ddd09d859792df3446ee7661cc1262b Mon Sep 17 00:00:00 2001 From: dkwiebe Date: Thu, 30 Jun 2022 20:20:05 -0600 Subject: [PATCH 6/9] Correct change to rememberForever --- src/SettingsServiceProvider.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SettingsServiceProvider.php b/src/SettingsServiceProvider.php index 900a60d..aa72162 100644 --- a/src/SettingsServiceProvider.php +++ b/src/SettingsServiceProvider.php @@ -48,13 +48,13 @@ public function boot() }); // only use the Settings package if the Settings table is present in the database - $tableExists = Cache::remember('backpack_settings_table_exists', config('backpack.settings.cache_time', 60), function () { + $tableExists = Cache::remember('backpack_settings_table_exists', function () { return Schema::hasTable(config('backpack.settings.table_name')); }); if (!\App::runningInConsole() && $tableExists) { // get all settings from the database if they're not in the database. - $settings = Cache::rememberForever('backpack_settings_cache', config('backpack.settings.cache_time', 60), function () { + $settings = Cache::rememberForever('backpack_settings_cache', function () { return Setting::all(); }); From 7889f04cb4b8207b051db2767910139a5f53d42e Mon Sep 17 00:00:00 2001 From: dkwiebe Date: Thu, 30 Jun 2022 20:32:37 -0600 Subject: [PATCH 7/9] Update SettingsServiceProvider.php --- src/SettingsServiceProvider.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SettingsServiceProvider.php b/src/SettingsServiceProvider.php index aa72162..c8c0a23 100644 --- a/src/SettingsServiceProvider.php +++ b/src/SettingsServiceProvider.php @@ -48,13 +48,13 @@ public function boot() }); // only use the Settings package if the Settings table is present in the database - $tableExists = Cache::remember('backpack_settings_table_exists', function () { + $tableExists = Cache::remember('backpack_settings_table_exists', config('backpack.settings.cache_time', 60), function () { return Schema::hasTable(config('backpack.settings.table_name')); }); if (!\App::runningInConsole() && $tableExists) { // get all settings from the database if they're not in the database. - $settings = Cache::rememberForever('backpack_settings_cache', function () { + $settings = Cache::remember('backpack_settings_cache', config('backpack.settings.cache_time', 60), function () { return Setting::all(); }); From a0d513e9944b5f506ed7cb7866b545b9dc3dd53f Mon Sep 17 00:00:00 2001 From: dkwiebe Date: Thu, 30 Jun 2022 20:41:23 -0600 Subject: [PATCH 8/9] Update settings.php --- src/config/backpack/settings.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/config/backpack/settings.php b/src/config/backpack/settings.php index 5cdf96c..925ca00 100644 --- a/src/config/backpack/settings.php +++ b/src/config/backpack/settings.php @@ -37,6 +37,16 @@ */ 'config_prefix' => 'settings', + /* + |-------------------------------------------------------------------------- + | Cache Time + |-------------------------------------------------------------------------- + | + | The cache time for storing settings in a cache rather than querying the database on each load. + | + */ + 'cache_time' => 60, + /* |-------------------------------------------------------------------------- | Migration file name From 25cc3a95a6ca5c4c86e787f20dcb2c868a761ce0 Mon Sep 17 00:00:00 2001 From: dkwiebe Date: Sat, 28 Jun 2025 11:14:50 -0600 Subject: [PATCH 9/9] Manually update cached settings --- .DS_Store | Bin 6148 -> 6148 bytes src/app/Console/Commands/CacheUpdate.php | 44 +++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/app/Console/Commands/CacheUpdate.php diff --git a/.DS_Store b/.DS_Store index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..7b68e4bb8751c138006d1da6dbc02c5d59eb24ff 100644 GIT binary patch literal 6148 zcmeHKy-or_5dKyUC2Astg@whnHYQZI2RR#UOz5Z-jvxu-2tSGCy@9sI$~W*GdWe22=r5XfOu5G_5iA^C;Ms-#H{S{ER`b z*6gIiQ6W+{Q~_1sFDk(AZh%wt(8pA~zuQkq-ZxC+xIIYQv{$(we>}gw&Fj*ieCr?G z=DrR450r|XFJ9bYhPGhG$zw4hUjvYJ>u0uxmFEo8WhI-VL_M(el&PLR5_EARYdN^1 zT5{f%I$D>m4iO=0SQ8=nuUL-~CK#h5xm)w4NAlwM!twe%dG1xO;4?4GSH_giI-z+Y zIq@#Nl6RqdE?;u5ixB*_-*5?Pzo-E9Y_`gtL!DItRX`P3D8S!`kOpJqF>`1?9W>c1 z0AWDe)@WVj1!3qh@|Za!51DbPgf7+iD~9o{!MJqtM?OAt=+a>AjHF;Q%yo+2v)5HN0TU~6aGtiZv}vavvwX)`+qKL=37W