+
+ /**
+ * @param string[] $keys
+ * @return bool
+ */
+ private function hadRecentSessionWrite( array $keys ) {
+ $now = $this->getCurrentTime();
+ foreach ( $keys as $key ) {
+ $ts = $this->lastKeyWrites[$key] ?? 0;
+ if ( $ts && ( $now - $ts ) <= $this->consistencyWindow ) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * @param string[] $keys
+ */
+ private function remarkRecentSessionWrite( array $keys ) {
+ $now = $this->getCurrentTime();
+ foreach ( $keys as $key ) {
+ unset( $this->lastKeyWrites[$key] ); // move to the end
+ $this->lastKeyWrites[$key] = $now;
+ }
+ // Prune out the map if the first key is obsolete
+ if ( ( $now - reset( $this->lastKeyWrites ) ) > $this->consistencyWindow ) {
+ $this->lastKeyWrites = array_filter(
+ $this->lastKeyWrites,
+ function ( $timestamp ) use ( $now ) {
+ return ( ( $now - $timestamp ) <= $this->consistencyWindow );
+ }
+ );
+ }
+ }