File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -126,6 +126,8 @@ public function has($key) : bool
126126class 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 }
You can’t perform that action at this time.
0 commit comments