Skip to content

feat: sharded peek, builder new(), ext alias parity, concurrent cache_try_get_or_set_with, retain on map stores - #294

Merged
jaemk merged 3 commits into
masterfrom
260720.pre-3.0-additive-parity
Jul 24, 2026
Merged

feat: sharded peek, builder new(), ext alias parity, concurrent cache_try_get_or_set_with, retain on map stores#294
jaemk merged 3 commits into
masterfrom
260720.pre-3.0-additive-parity

Conversation

@jaemk

@jaemk jaemk commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Additive API parity ahead of 3.0.0 final. Stacked on #293.

  • Add inherent peek(&self, &K) -> Option<V> to all six sharded stores: clone of the live value, no recency/TTL/metrics effects, no lazy removal of expired entries.
  • Add Builder::new() to the 13 in-memory and sharded builders, equivalent to the store's ::builder() (parity with the IO builders' public constructors).
  • Add CachedExt::capacity/evictions and ConcurrentCachedExt::len/is_empty/hits/misses/capacity/evictions aliases.
  • Add provided ConcurrentCached::cache_try_get_or_set_with and ConcurrentCachedAsync::async_cache_try_get_or_set_with: fallible-init get-or-set returning Result<Result<V, E>, Self::Error> (store error outer, closure error inner; nothing stored on closure Err).
  • Add retain(keep) to TtlCache/ExpiringCache; expired entries are dropped regardless of the predicate. UnboundCache gets no retain: it has no eviction dimension backing the operation.
  • Add TtlSortedCache::capacity() and the missing doc(alias = "capacity") on its builder's max_size.
  • Update specs; traits-concurrent also drops the wrong AsyncRedisCache listing under the sync cache_contains and a garbled parenthetical.
  • Add tests/v3_additive_parity.rs covering all of the above.

…et*`, wrap order-method values in `CacheValue`

Breaking changes ahead of 3.0.0 final:

- remove `CacheSetError`: a TTL that would overflow `Instant` bounds now
  stores the entry with no expiry (never expires) on every set path,
  matching the sharded TTL stores (`cache_set` already behaved this way).
  `TtlCache` / `LruTtlCache` / `TtlSortedCache` set
  `Cached::Error = Infallible`, so every built-in in-memory store is
  infallible; the `type Error` machinery remains for custom and IO stores.
- rename `TtlSortedCache::insert` / `insert_ttl` / `insert_evict` /
  `insert_ttl_evict` to `set` / `set_with_ttl` / `set_evict` /
  `set_with_ttl_evict`, returning `Option<V>` instead of `Result`.
- unify the LRU-family order methods on one shape:
  `iter_order() -> Vec<(K, CacheValue<V, M>)>` and
  `value_order() -> Vec<CacheValue<V, M>>` on `LruCache`, `LruTtlCache`,
  and `ExpiringLruCache`. `CacheValue<V, M = ()>` (new root re-export)
  derefs to `V`, compares against bare values, and exposes per-entry
  metadata via typed accessors: `expires_at()` on `LruTtlCache` entries
  (`M = Option<Instant>`). `LruTtlCache` no longer leaks bare
  `(Option<Instant>, V)` tuples.

Migration guide sections 18/22/33/43 updated and 74/75 added; design doc
0020 closed out (error split kept, `TimeBounds` gone).
…cache_try_get_or_set_with`, `retain` on map stores
@jaemk
jaemk force-pushed the 260720.pre-3.0-additive-parity branch from ca91f18 to ffbecc1 Compare July 21, 2026 12:40
@jaemk
jaemk deleted the branch master July 23, 2026 23:57
@jaemk jaemk closed this Jul 23, 2026
@jaemk jaemk reopened this Jul 23, 2026
@jaemk
jaemk changed the base branch from 260719.pre-3.0-breaking-polish to master July 23, 2026 23:58
@jaemk
jaemk merged commit 1792dfc into master Jul 24, 2026
1 check passed
@jaemk
jaemk deleted the 260720.pre-3.0-additive-parity branch July 24, 2026 00:18
jaemk added a commit that referenced this pull request Jul 25, 2026
…ocsrs badges, doc and spec corrections (#296)

- `#[cached]` on a non-`Clone` return type now emits a `Clone`-bound error spanned
  at the return type (a compile-time assertion on the cached value type, including
  `Return<T>` under `with_cached_flag`), ahead of the opaque errors from the
  generated internals. Trybuild tests cover the plain and `with_cached_flag`
  negative cases plus a generic-function positive case.
- add the missing `doc(cfg(feature = "async_core"))` badges on the
  `CachedGetOrSetAsync` / `ConcurrentCachedAsync` impls for the in-memory and
  sharded stores and `HashMap`, so docs.rs marks them feature-gated.
- correct the changelog and `specs/store-lru.md` claim that `UnboundCache` has no
  `retain` (it shipped in #294); document the `UnboundCache` semantics (predicate
  filter, fires `on_evict`, no eviction counter).
- migration guides: fix the `cache_peek_with_expiry_status` sibling name, reword
  the rc-era no-arg builder note, and add human-guide sections for
  `CacheTtl`/`CacheEvict` removal from concurrent stores and the redis
  empty-prefix `InvalidValue` rejection.
- specs: add LRU-5/TTL-5/EXPIRE-6 covering `iter_order`/`value_order`/`CacheValue`;
  mark design 0020 Declined in the index.
- document the lookup-key difference between the trait families
  (`&Q where K: Borrow<Q>` on `Cached` vs `&K` on `ConcurrentCached`) in the
  lib.rs comparison docs; README regenerated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant