mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Fix runtime cache (#16272)
Fix runtime cache when redis is enabled, but not running
This commit is contained in:
@ -27,7 +27,6 @@
|
||||
namespace LibreNMS\Traits;
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use LibreNMS\Util\Laravel;
|
||||
|
||||
trait RuntimeClassCache
|
||||
{
|
||||
@ -45,9 +44,18 @@ trait RuntimeClassCache
|
||||
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();
|
||||
if ($this->runtimeCacheExternalTTL) {
|
||||
try {
|
||||
$this->runtimeCache[$name] = Cache::remember('runtimeCache' . __CLASS__ . $name, $this->runtimeCacheExternalTTL, $actual);
|
||||
|
||||
return $this->runtimeCache[$name]; // system cache success, don't use local cache
|
||||
} catch (\Exception $e) {
|
||||
// go to fallback code
|
||||
}
|
||||
}
|
||||
|
||||
// non-persistent cache
|
||||
$this->runtimeCache[$name] = $actual();
|
||||
}
|
||||
|
||||
return $this->runtimeCache[$name];
|
||||
|
Reference in New Issue
Block a user