From 9bd0dda3dd2e4604531b20f36111951dc40e7680 Mon Sep 17 00:00:00 2001 From: FreeScout Date: Tue, 27 Nov 2018 22:05:13 -0800 Subject: [PATCH] Fix options caching --- app/Option.php | 25 ++++++++++++++++++++----- public/css/style.css | 3 +++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/Option.php b/app/Option.php index 8915bed5..1991b909 100644 --- a/app/Option.php +++ b/app/Option.php @@ -9,6 +9,9 @@ use Illuminate\Database\Eloquent\Model; class Option extends Model { + // Value returned when cache contains default value. + const CACHE_DEFAULT_VALUE = 'CACHE_DEFAULT_VALUE'; + // todo: cache like in WordPress (fetch all options from DB each time) public static $cache = []; @@ -76,7 +79,11 @@ class Option extends Model } if (isset(self::$cache[$name])) { - return self::$cache[$name]; + if (self::$cache[$name] == self::CACHE_DEFAULT_VALUE) { + return $default; + } else { + return self::$cache[$name]; + } } $option = self::where('name', (string) $name)->first(); @@ -86,12 +93,12 @@ class Option extends Model } else { $value = $option->value; } + self::$cache[$name] = $value; } else { $value = $default; + self::$cache[$name] = self::CACHE_DEFAULT_VALUE; } - self::$cache[$name] = $value; - return $value; } @@ -142,7 +149,14 @@ class Option extends Model // Return if we can get all options from cache foreach ($options as $name) { if (isset(self::$cache[$name])) { - $values[$name] = self::$cache[$name]; + if (self::$cache[$name] == self::CACHE_DEFAULT_VALUE) { + if (empty($defaults[$name])) { + $default = self::getDefault($name); + } + $values[$name] = $default; + } else { + $values[$name] = self::$cache[$name]; + } } } if (count($values) == count($options)) { @@ -165,11 +179,12 @@ class Option extends Model } else { $value = $db_option->value; } + self::$cache[$name] = $value; } else { $value = $default; + self::$cache[$name] = self::CACHE_DEFAULT_VALUE; } - self::$cache[$name] = $value; $values[$name] = $value; } diff --git a/public/css/style.css b/public/css/style.css index e09f88a7..315188a8 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -2718,6 +2718,9 @@ ul.prev-convs { .margin-bottom-0 { margin-bottom: 0 !important; } +.margin-bottom-10 { + margin-bottom: 10px !important; +} .margin-bottom-30 { margin-bottom: 30px !important; }