Answer the question
In order to leave comments, you need to log in
How to cache variables at php level?
there is this code:
static $graph = false;
if($graph !== false){
return $graph;
}
$graph = DB::getRecords();
return $graph;
Answer the question
In order to leave comments, you need to log in
What exactly to remove? too big code?, wrap it in a function passing the variable name in the arguments:
function cache($name,$callback)
{
static $cache = [];
if(isset($cache[$name])) return $cache[$name];
return $cache[$name] = $callback();
}
var_dump(cache('graph',fn()=>DB::getRecords()));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question