From dd64670987063aa5c06e4269597eb18dda227518 Mon Sep 17 00:00:00 2001 From: Niklas Keller Date: Tue, 20 Jun 2017 17:40:47 +0200 Subject: [PATCH] Make StatCache compatible with loop resets --- lib/StatCache.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/StatCache.php b/lib/StatCache.php index 3d305d1..596f4b3 100644 --- a/lib/StatCache.php +++ b/lib/StatCache.php @@ -9,11 +9,11 @@ class StatCache { private static $timeouts = []; private static $ttl = 3; private static $now = null; - private static $isInitialized = false; private static function init() { - self::$isInitialized = true; + Loop::setState(self::class, true); self::$now = \time(); + $watcher = Loop::repeat(1000, function () { self::$now = $now = \time(); foreach (self::$cache as $path => $expiry) { @@ -27,6 +27,7 @@ class StatCache { } } }); + Loop::unreference($watcher); } @@ -38,9 +39,11 @@ class StatCache { if (self::$ttl <= 0) { return; } - if (empty(self::$isInitialized)) { + + if (Loop::getState(self::class) === null) { self::init(); } + self::$cache[$path] = $stat; self::$timeouts[$path] = self::$now + self::$ttl; }