* A StatsCounter implementation that maintains cache statistics.
| 287 | * A StatsCounter implementation that maintains cache statistics. |
| 288 | */ |
| 289 | class 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 | * |
nothing calls this directly
no outgoing calls
no test coverage detected