@@ -35,21 +35,22 @@ public function __construct(string $namespace = 'cache')
3535 * @param string $key Cache key
3636 * @param float $microtime Time taken in microseconds
3737 */
38- public function recordHit (string $ key , $ microtime ): void
38+ public function recordHit (string $ key , $ microtime, array $ labels = [] ): void
3939 {
4040 $ sanitizedKey = $ this ->sanitizeKey ($ key );
41+ $ labelKeys = array_keys ($ labels );
4142
4243 $ this ->metrics ->counter (
4344 'cache_hits_total ' ,
4445 'Total number of cache hits ' ,
45- ['cache_key ' ]
46- )->inc (['cache_key ' => $ sanitizedKey ]);
46+ ['cache_key ' , ... $ labelKeys ]
47+ )->inc (['cache_key ' => $ sanitizedKey, ... $ labels ]);
4748 // record the last write timestamp
4849 $ this ->metrics ->gauge (
4950 'cache_last_write_timestamp ' ,
5051 'Last write timestamp ' ,
51- ['cache_key ' ]
52- )->set ($ microtime , ['cache_key ' => $ sanitizedKey ]);
52+ ['cache_key ' , ... $ labelKeys ]
53+ )->set ($ microtime , ['cache_key ' => $ sanitizedKey, ... $ labels ]);
5354 }
5455
5556 /**
@@ -58,22 +59,23 @@ public function recordHit(string $key, $microtime): void
5859 * @param string $key Cache key
5960 * @param float $microtime Time taken in microseconds
6061 */
61- public function recordMiss (string $ key , $ microtime ): void
62+ public function recordMiss (string $ key , $ microtime, array $ labels = [] ): void
6263 {
6364 $ sanitizedKey = $ this ->sanitizeKey ($ key );
65+ $ labelKeys = array_keys ($ labels );
6466
6567 $ this ->metrics ->counter (
6668 'cache_misses_total ' ,
6769 'Total number of cache misses ' ,
68- ['cache_key ' ]
69- )->inc (['cache_key ' => $ sanitizedKey ]);
70+ ['cache_key ' , ... $ labelKeys ]
71+ )->inc (['cache_key ' => $ sanitizedKey, ... $ labels ]);
7072
7173 // record the last write timestamp
7274 $ this ->metrics ->gauge (
7375 'cache_last_write_timestamp ' ,
7476 'Last write timestamp ' ,
75- ['cache_key ' ]
76- )->set ($ microtime , ['cache_key ' => $ sanitizedKey ]);
77+ ['cache_key ' , ... $ labelKeys ]
78+ )->set ($ microtime , ['cache_key ' => $ sanitizedKey, ... $ labels ]);
7779 }
7880
7981 /**
@@ -82,15 +84,16 @@ public function recordMiss(string $key, $microtime): void
8284 * @param string $key Cache key
8385 * @param int $size Size in bytes
8486 */
85- public function recordWrite (string $ key , int $ size ): void
87+ public function recordWrite (string $ key , int $ size, array $ labels = [] ): void
8688 {
8789 $ sanitizedKey = $ this ->sanitizeKey ($ key );
90+ $ labelKeys = array_keys ($ labels );
8891
8992 $ this ->metrics ->gauge (
9093 'cache_memory_bytes ' ,
9194 'Memory usage in bytes ' ,
92- ['cache_key ' ]
93- )->set ($ size , ['cache_key ' => $ sanitizedKey ]);
95+ ['cache_key ' , ... $ labelKeys ]
96+ )->set ($ size , ['cache_key ' => $ sanitizedKey, ... $ labels ]);
9497 }
9598
9699 /**
0 commit comments