. * * @link https://www.librenms.org * * @copyright 2022 Tony Murray * @author Tony Murray */ namespace LibreNMS\Traits; use Illuminate\Support\Facades\Cache; use LibreNMS\Util\Laravel; trait RuntimeClassCache { /** @var array */ private $runtimeCache = []; /** @var int Setting this installs the data in the external cache to be shared across instances */ protected $runtimeCacheExternalTTL = 0; /** * We want these each runtime, so don't use the global cache * * @return mixed */ protected function cacheGet(string $name, callable $actual) { if (! array_key_exists($name, $this->runtimeCache)) { $this->runtimeCache[$name] = $this->runtimeCacheExternalTTL && Laravel::isBooted() ? Cache::remember('runtimeCache' . __CLASS__ . $name, $this->runtimeCacheExternalTTL, $actual) : $actual(); } return $this->runtimeCache[$name]; } }