Skip to content

feat: TtlSortedCache::set_with builder, ConcurrentCachePeek, ConcurrentCachedExt::try_get_or_set_with - #297

Merged
jaemk merged 1 commit into
masterfrom
260725.pre-3.0-api-round
Jul 25, 2026
Merged

feat: TtlSortedCache::set_with builder, ConcurrentCachePeek, ConcurrentCachedExt::try_get_or_set_with#297
jaemk merged 1 commit into
masterfrom
260725.pre-3.0-api-round

Conversation

@jaemk

@jaemk jaemk commented Jul 25, 2026

Copy link
Copy Markdown
Owner

Three v3 API changes plus a macro cleanup.

  • Replace the TtlSortedCache inherent setters set_with_ttl / set_evict / set_with_ttl_evict with an entry-setter builder: cache.set_with(k, v).ttl(d).evict().set(). set_with_ttl_evict took Option<Duration> while set_with_ttl took a bare Duration; the builder makes each option independent and gives one spelling per combination. Plain set(k, v) and Cached::cache_set are unchanged. TtlSortedSetBuilder is re-exported at the crate root and from cached::stores, gated on time_stores.
  • Add ConcurrentCachePeek<K, V>, moving the sharded peek onto a trait so generic code over a concurrent store can read without side effects: no recency promotion, no TTL refresh, no hit/miss metrics, no lazy removal of expired entries. Implemented by the six sharded stores only (Error = Infallible); the IO stores are excluded because they cannot peek without a full read. The concrete sharded types keep their inherent peek, which retains call-site priority. Exported from the prelude.
  • Add ConcurrentCachedExt::try_get_or_set_with, completing the short-alias set for ConcurrentCached::cache_try_get_or_set_with to match CachedExt.
  • Remove a no-op #[allow(non_snake_case)] from the #[cached] Clone assertion expansion.

Breaking changes are covered in the changelog and both migration guides. New coverage is in tests/v3_ttl_sorted_set_with.rs and tests/v3_additive_parity.rs.

…currentCachedExt::try_get_or_set_with`

Breaking: the `TtlSortedCache` inherent setters `set_with_ttl`, `set_evict`, and
`set_with_ttl_evict` are replaced by a single entry-setter builder,
`set_with(k, v).ttl(d).evict().set()`. `set_with_ttl_evict` took `Option<Duration>`
while `set_with_ttl` took a bare `Duration`; the builder makes each option
independent and gives one spelling per combination. Plain `set(k, v)` and
`Cached::cache_set` are unchanged. `TtlSortedSetBuilder` is re-exported at the
crate root and from `cached::stores`, gated on `time_stores`.

`ConcurrentCachePeek<K, V>` moves the sharded `peek` onto a trait so generic code
over a concurrent store can read without side effects: no recency promotion, no
TTL refresh, no hit/miss metrics, and no lazy removal of expired entries. Only
the six sharded stores implement it (`Error = Infallible`); the IO stores are
excluded because they cannot peek without a full read. The concrete sharded types
keep their inherent `peek`, which retains call-site priority.

`ConcurrentCachedExt::try_get_or_set_with` completes the short-alias set for
`ConcurrentCached::cache_try_get_or_set_with`, mirroring `CachedExt`.

Also drops a no-op `#[allow(non_snake_case)]` from the `#[cached]` `Clone`
assertion expansion.
@jaemk
jaemk merged commit 2afc655 into master Jul 25, 2026
1 check passed
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