All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog.
V remove(K key)- removes an entry and returns its live value (ornullif absent/expired). Not counted as a hit or miss.V computeIfAbsent(K key, Function<? super K, ? extends V> loader)and an overload taking an explicitlong ttlMillis- returns the cached value or computes, stores and returns it. Runs under the cache lock, so concurrent callers for the same key run the loader once. Counts as one hit or miss. Anullresult or an exception stores nothing.List<K> keys()- snapshot of live keys, least- to most-recently-used, with no effect on recency or statistics.
- Cache hit/miss statistics on
LruCache:long hitCount()- lifetime count ofget()calls that found a live, non-expired entry.long missCount()- lifetime count ofget()calls that found nothing (key absent, or present but TTL-expired).double hitRate()-hitCount / (hitCount + missCount), returning0.0before the firstget()call to avoid dividing by zero.- Following Guava's
CacheStatsconvention, these counters are cumulative for the life of the cache instance and are not reset byput()orclear().
- New README "Cache Statistics" section with a runnable example, plus a
second
## Usageexample (a cache-in-front-of-a-lookup pattern). - New hand-calculated test (
testHitAndMissCountsWithExactExpectedValues) that walks a specific sequence of puts and gets - including a capacity-triggered eviction and a post-clear()get - and asserts exact expectedhitCount(),missCount(), andhitRate()values.
- Test coverage for documented-but-untested
LruCacheedge cases:- The constructor rejects a capacity less than 1 (
0and negative values) withIllegalArgumentException. size()is confirmed to count an expired-but-not-yet-purged entry (purging only happens lazily insideget()), matching the documented contract.- Re-putting an already-present key does not grow the cache past capacity or evict any other entry.
- The constructor rejects a capacity less than 1 (
No behavioral changes were needed — all new edge-case tests passed against the existing implementation.