MCPcopy
hub / github.com/redis/node-redis / DefaultStatsCounter

Class DefaultStatsCounter

packages/client/lib/client/cache.ts:289–368  ·  view source on GitHub ↗

* A StatsCounter implementation that maintains cache statistics.

Source from the content-addressed store, hash-verified

287 * A StatsCounter implementation that maintains cache statistics.
288 */
289class DefaultStatsCounter implements StatsCounter {
290 #hitCount = 0;
291 #missCount = 0;
292 #loadSuccessCount = 0;
293 #loadFailureCount = 0;
294 #totalLoadTime = 0;
295 #evictionCount = 0;
296
297 /**
298 * Records cache hits.
299 *
300 * @param count - The number of hits to record
301 */
302 recordHits(count: number): void {
303 this.#hitCount += count;
304 }
305
306 /**
307 * Records cache misses.
308 *
309 * @param count - The number of misses to record
310 */
311 recordMisses(count: number): void {
312 this.#missCount += count;
313 }
314
315 /**
316 * Records the successful load of a new entry.
317 *
318 * @param loadTime - The number of milliseconds spent loading the entry
319 */
320 recordLoadSuccess(loadTime: number): void {
321 this.#loadSuccessCount++;
322 this.#totalLoadTime += loadTime;
323 }
324
325 /**
326 * Records the failed load of a new entry.
327 *
328 * @param loadTime - The number of milliseconds spent attempting to load the entry
329 */
330 recordLoadFailure(loadTime: number): void {
331 this.#loadFailureCount++;
332 this.#totalLoadTime += loadTime;
333 }
334
335 /**
336 * Records cache evictions.
337 *
338 * @param count - The number of evictions to record
339 */
340 recordEvictions(count: number): void {
341 this.#evictionCount += count;
342 }
343
344 /**
345 * Returns a snapshot of the current statistics.
346 *

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected