mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Utils::getFromCache speedup via static variable cache
(cherry picked from commit 7d65f8b1b726075626476501a4a58540e3aeb71f)
This commit is contained in:
parent
4476c9eea2
commit
de6919d37c
@ -22,6 +22,8 @@ use Nwidart\Modules\Facades\Module;
|
|||||||
|
|
||||||
class Utils
|
class Utils
|
||||||
{
|
{
|
||||||
|
protected static $cacheValues = [];
|
||||||
|
|
||||||
private static $weekdayNames = [
|
private static $weekdayNames = [
|
||||||
'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday',
|
'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday',
|
||||||
];
|
];
|
||||||
@ -555,6 +557,9 @@ class Utils
|
|||||||
|
|
||||||
public static function getFromCache($id, $type)
|
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);
|
$cache = Cache::get($type);
|
||||||
|
|
||||||
if (! $cache) {
|
if (! $cache) {
|
||||||
@ -567,7 +572,11 @@ class Utils
|
|||||||
return $item->id == $id;
|
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)
|
public static function formatNumber($value, $currencyId = false, $precision = 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user