31 lines
330 B
PHP
31 lines
330 B
PHP
|
<?php
|
||
|
|
||
|
namespace rosavox\helpers\cache;
|
||
|
|
||
|
|
||
|
/**
|
||
|
*/
|
||
|
class state
|
||
|
{
|
||
|
public static array $pool = [];
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
*/
|
||
|
function get(string $key, \Closure $retrieve)
|
||
|
{
|
||
|
if (\array_key_exists($key, state::$pool))
|
||
|
{
|
||
|
$value = state::$pool[$key];
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
$value = ($retrieve)();
|
||
|
state::$pool[$key] = $value;
|
||
|
}
|
||
|
return $value;
|
||
|
}
|
||
|
|
||
|
?>
|