Releases: kasapdev/java-simple-cache
Releases · kasapdev/java-simple-cache
Release list
v1.3.0
Added
V remove(K key)- removes an entry and returns its live value (ornull
if 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. A
nullresult or an exception stores nothing.List<K> keys()- snapshot of live keys, least- to most-recently-used, with
no effect on recency or statistics.
v1.2.0
Added
Cache hit/miss statistics on LruCache<K, V>:
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)as adouble; returns0.0before the firstget()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
## Usageexample (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 exacthitCount(),missCount(), andhitRate()values.
No breaking changes. All existing tests continue to pass unmodified.