mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Merge pull request #12326 from uberbrady/uncache_settings
The cache system in getSettings() cached values "forever." That's bad.
This commit is contained in:
commit
20a9be2f6c
|
@ -21,11 +21,10 @@ class Setting extends Model
|
||||||
use Notifiable, ValidatingTrait;
|
use Notifiable, ValidatingTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The app settings cache key name.
|
* The cache property so that multiple invocations of this will only load the Settings record from disk only once
|
||||||
*
|
* @var self
|
||||||
* @var string
|
|
||||||
*/
|
*/
|
||||||
const APP_SETTINGS_KEY = 'snipeit_app_settings';
|
public static ?self $_cache = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The setup check cache key name.
|
* The setup check cache key name.
|
||||||
|
@ -98,14 +97,15 @@ class Setting extends Model
|
||||||
*/
|
*/
|
||||||
public static function getSettings(): ?self
|
public static function getSettings(): ?self
|
||||||
{
|
{
|
||||||
return Cache::rememberForever(self::APP_SETTINGS_KEY, function () {
|
if (!self::$_cache) {
|
||||||
// Need for setup as no tables exist
|
// Need for setup as no tables exist
|
||||||
try {
|
try {
|
||||||
return self::first();
|
self::$_cache = self::first();
|
||||||
} catch (\Throwable $th) {
|
} catch (\Throwable $th) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
return self::$_cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -16,7 +16,6 @@ class SettingObserver
|
||||||
*/
|
*/
|
||||||
public function saved(Setting $setting)
|
public function saved(Setting $setting)
|
||||||
{
|
{
|
||||||
Cache::forget(Setting::APP_SETTINGS_KEY);
|
|
||||||
Cache::forget(Setting::SETUP_CHECK_KEY);
|
Cache::forget(Setting::SETUP_CHECK_KEY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue