1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 08:21:34 +02:00

Utils::getFromCache speedup via static variable cache

(cherry picked from commit 7d65f8b1b7)
This commit is contained in:
Aleksander V. Dyomin 2019-08-05 12:33:56 +03:00
parent 4476c9eea2
commit de6919d37c

View File

@ -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)