From de6919d37c8eb79ecc17b0518a96a6b927d39032 Mon Sep 17 00:00:00 2001 From: "Aleksander V. Dyomin" Date: Mon, 5 Aug 2019 12:33:56 +0300 Subject: [PATCH] Utils::getFromCache speedup via static variable cache (cherry picked from commit 7d65f8b1b726075626476501a4a58540e3aeb71f) --- app/Libraries/Utils.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/Libraries/Utils.php b/app/Libraries/Utils.php index 121e3cc5d6fd..5f2f61d543c0 100644 --- a/app/Libraries/Utils.php +++ b/app/Libraries/Utils.php @@ -22,6 +22,8 @@ use Nwidart\Modules\Facades\Module; class Utils { + protected static $cacheValues = []; + private static $weekdayNames = [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', ]; @@ -555,6 +557,9 @@ class Utils public static function getFromCache($id, $type) { + if (!empty(static::$cacheValues[$type]) && !empty(static::$cacheValues[$type][$id])) { + return static::$cacheValues[$type][$id]; + } $cache = Cache::get($type); if (! $cache) { @@ -567,7 +572,11 @@ class Utils return $item->id == $id; }); - return $data->first(); + $res = $data->first(); + if (!empty($res)) { + static::$cacheValues[$type][$id] = $res; + } + return $res; } public static function formatNumber($value, $currencyId = false, $precision = 0)