Settings::clearCache function

This commit is contained in:
slawkens 2024-02-04 08:35:33 +01:00
parent 649e37ab0f
commit 235e69b8da

View File

@ -38,8 +38,7 @@ class Settings implements \ArrayAccess
} }
$settings = ModelsSettings::all(); $settings = ModelsSettings::all();
foreach ($settings as $setting) foreach ($settings as $setting) {
{
$this->settingsDatabase[$setting->name][$setting->key] = $setting->value; $this->settingsDatabase[$setting->name][$setting->key] = $setting->value;
} }
@ -93,11 +92,7 @@ class Settings implements \ArrayAccess
} }
} }
$cache = Cache::getInstance(); $this->clearCache();
if ($cache->enabled()) {
$cache->delete('settings');
}
return true; return true;
} }
@ -110,6 +105,8 @@ class Settings implements \ArrayAccess
// insert new // insert new
ModelsSettings::create(['name' => $pluginName, 'key' => $key, 'value' => $value]); ModelsSettings::create(['name' => $pluginName, 'key' => $key, 'value' => $value]);
} }
$this->clearCache();
} }
public function deleteFromDatabase($pluginName, $key = null) public function deleteFromDatabase($pluginName, $key = null)
@ -120,6 +117,8 @@ class Settings implements \ArrayAccess
else { else {
ModelsSettings::where('name', $pluginName)->where('key', $key)->delete(); ModelsSettings::where('name', $pluginName)->where('key', $key)->delete();
} }
$this->clearCache();
} }
public static function display($plugin, $settings): array public static function display($plugin, $settings): array
@ -604,4 +603,12 @@ class Settings implements \ArrayAccess
public function getErrors() { public function getErrors() {
return $this->errors; return $this->errors;
} }
public function clearCache(): void
{
$cache = Cache::getInstance();
if ($cache->enabled()) {
$cache->delete('settings');
}
}
} }