Skip to content

Commit bc47396

Browse files
fix(demo): Fix /api/stats hits/misses tracking
1 parent 911f353 commit bc47396

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

public/index.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ public function has($key) : bool
126126
class StatusTracker
127127
{
128128
public ?string $lastStatus = null;
129+
public int $hits = 0;
130+
public int $misses = 0;
129131
}
130132
$tracker = new StatusTracker();
131133

@@ -136,6 +138,16 @@ public function dispatch(object $event) : object
136138
{
137139
if ($event instanceof \Fyennyi\AsyncCache\Event\CacheStatusEvent) {
138140
$this->tracker->lastStatus = $event->status->value;
141+
// Hit, Stale, XFetch = cache hits; Miss = cache miss
142+
if (in_array($event->status, [
143+
\Fyennyi\AsyncCache\Enum\CacheStatus::Hit,
144+
\Fyennyi\AsyncCache\Enum\CacheStatus::Stale,
145+
\Fyennyi\AsyncCache\Enum\CacheStatus::XFetch,
146+
], true)) {
147+
$this->tracker->hits++;
148+
} elseif ($event->status === \Fyennyi\AsyncCache\Enum\CacheStatus::Miss) {
149+
$this->tracker->misses++;
150+
}
139151
}
140152
return $event;
141153
}

0 commit comments

Comments
 (0)