From 2d0ac5b48bfe3ad5a033dca2e9508e91126d5909 Mon Sep 17 00:00:00 2001 From: Brady Wetherington Date: Mon, 9 Jan 2023 16:16:09 -0800 Subject: [PATCH 1/2] The cache system in getSettings() cached values "forever." That's bad. --- app/Models/Setting.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/Models/Setting.php b/app/Models/Setting.php index 06083ad50..f2a418417 100755 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -21,11 +21,10 @@ class Setting extends Model use Notifiable, ValidatingTrait; /** - * The app settings cache key name. - * - * @var string + * The cache property so that multiple invocations of this will only load the Settings record from disk only once + * @var self */ - const APP_SETTINGS_KEY = 'snipeit_app_settings'; + public static ?self $_cache = null; /** * The setup check cache key name. @@ -98,14 +97,15 @@ class Setting extends Model */ public static function getSettings(): ?self { - return Cache::rememberForever(self::APP_SETTINGS_KEY, function () { + if (!self::$_cache) { // Need for setup as no tables exist try { - return self::first(); + self::$_cache = self::first(); } catch (\Throwable $th) { return null; } - }); + } + return self::$_cache; } /** From 39b1a5a8a0e21667830aa7d108c7c1d543dee845 Mon Sep 17 00:00:00 2001 From: Brady Wetherington Date: Mon, 9 Jan 2023 16:19:25 -0800 Subject: [PATCH 2/2] Remove old cache key for settings --- app/Observers/SettingObserver.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Observers/SettingObserver.php b/app/Observers/SettingObserver.php index aeb682a03..ec9dec3f2 100644 --- a/app/Observers/SettingObserver.php +++ b/app/Observers/SettingObserver.php @@ -16,7 +16,6 @@ class SettingObserver */ public function saved(Setting $setting) { - Cache::forget(Setting::APP_SETTINGS_KEY); Cache::forget(Setting::SETUP_CHECK_KEY); } }