Skip to content

v1.2.0

Choose a tag to compare

@kasapdev kasapdev released this 07 Sep 20:03
· 1 commit to main since this release

Added

Cache hit/miss statistics on LruCache<K, V>:

  • long hitCount() - lifetime count of get() calls that found a live, non-expired entry.
  • long missCount() - lifetime count of get() calls that found nothing (key absent, or present but TTL-expired).
  • double hitRate() - hitCount / (hitCount + missCount) as a double; returns 0.0 before the first get() call to avoid dividing by zero.

Every call to get() updates these counters automatically - a hit for a live entry, a miss for an absent or expired one. Following Guava's CacheStats convention, the counters are cumulative for the life of the cache instance and are intentionally not reset by put() or clear() (documented in the class javadoc and the README).

Also adds:

  • A "Cache Statistics" section to the README with a runnable example, and a second ## Usage example (a lookup-cache pattern).
  • A hand-calculated regression test that walks a specific put/get sequence - including a capacity-triggered eviction and a post-clear() get - and asserts exact hitCount(), missCount(), and hitRate() values.

No breaking changes. All existing tests continue to pass unmodified.