Skip to content

feat: expiring ttl cache#263

Open
jaemk wants to merge 1 commit into
masterfrom
260522.expires-ttl-once
Open

feat: expiring ttl cache#263
jaemk wants to merge 1 commit into
masterfrom
260522.expires-ttl-once

Conversation

@jaemk
Copy link
Copy Markdown
Owner

@jaemk jaemk commented May 23, 2026

No description provided.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 23, 2026

Merging this PR will not alter performance

⚡ 1 improved benchmark
❌ 1 regressed benchmark
✅ 12 untouched benchmarks
🆕 2 new benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
🆕 ExpiringCache hit (O(1)) N/A 402.8 ns N/A
UnboundCache insert 468.6 ns 410.3 ns +14.22%
UnboundCache hit 247.2 ns 276.4 ns -10.55%
🆕 ExpiringCache insert N/A 408.3 ns N/A

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing 260522.expires-ttl-once (e28bbcd) with master (f4c7bae)

Open in CodSpeed

This comment was marked as resolved.

@jaemk jaemk force-pushed the 260522.expires-ttl-once branch from 3d75e50 to df216b1 Compare May 23, 2026 14:51
@jaemk jaemk requested a review from Copilot May 23, 2026 14:51

This comment was marked as resolved.

@jaemk jaemk force-pushed the 260522.expires-ttl-once branch from df216b1 to 9059a2b Compare May 23, 2026 15:07
@jaemk jaemk requested a review from Copilot May 23, 2026 15:07

This comment was marked as resolved.

@jaemk jaemk force-pushed the 260522.expires-ttl-once branch from 9059a2b to 2e9a585 Compare May 23, 2026 15:32
@jaemk jaemk requested a review from Copilot May 23, 2026 15:47

This comment was marked as resolved.

@jaemk jaemk force-pushed the 260522.expires-ttl-once branch 3 times, most recently from a4db062 to 8e250b3 Compare May 24, 2026 02:36
@jaemk jaemk requested a review from Copilot May 24, 2026 02:36
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 41 out of 41 changed files in this pull request and generated 1 comment.

Comment thread src/stores/expiring_lru.rs Outdated
@jaemk jaemk force-pushed the 260522.expires-ttl-once branch from 8e250b3 to 7f08b62 Compare May 24, 2026 04:52
@jaemk jaemk requested a review from Copilot May 24, 2026 04:53
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 41 out of 41 changed files in this pull request and generated 3 comments.

Comment thread examples/expires_per_key.rs
Comment thread examples/expires_per_key.rs
Comment thread examples/expires_per_key.rs
…ttribute

Adds a new size-unbounded `ExpiringCache<K,V>` store (and `ExpiringCacheBuilder`)
alongside the existing `ExpiringLruCache<K,V>`, both using the `Expires` trait
for per-value expiration rather than a global TTL duration.

Extends `#[cached]` with `expires = true`: automatically selects `ExpiringCache`
(unbounded) or `ExpiringLruCache` (when `size` is also set). Compatible with
`result`, `option`, `result_fallback`, `sync_writes`, `key`/`convert`, and `size`.
Mutually exclusive with `ttl`, `ty`, `create`, `with_cached_flag`, `unsync_reads`,
`refresh`, and `unbound`.

Also adds `expires = true` to `#[once]` for single-value caches using the same
per-value expiry mechanism.

Other additions:
- Compile-fail trybuild tests for all mutual exclusions
- Smoke tests in `expires_macro_tests` (proc_macro only, no time_stores dependency)
- Integration tests in `time_store_tests` for result/option/result_fallback paths
- Debug + Clone impls for `ExpiringCache`
- Standardized micro-benchmarks across all 7 core in-memory stores
- `examples/expires_per_key.rs` demonstrating all four expiry patterns
- Documentation and quickstart in lib.rs / README.md
- CHANGELOG entry under [Unreleased]
@jaemk jaemk force-pushed the 260522.expires-ttl-once branch from 7f08b62 to e28bbcd Compare May 24, 2026 05:59
@jaemk jaemk requested a review from Copilot May 24, 2026 06:00
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 42 out of 42 changed files in this pull request and generated 3 comments.

Comment on lines +58 to +62
/// - `expires`: (optional, bool) Auto-select an expiry-aware store whose entries expire based on
/// per-value logic rather than a single global TTL.
/// The return type (or its inner type when `result`/`option` is also set) must implement [`cached::Expires`].
/// Without `size`, uses [`cached::ExpiringCache`] (unbounded).
/// With `size = N`, uses [`cached::ExpiringLruCache`] (LRU-bounded to N entries).
Comment on lines +100 to +102
/// - `expires`: (optional, bool) Delegate expiry to the cached value instead of a fixed TTL.
/// The return type (or its inner type when `result`/`option` is also set) must implement [`cached::Expires`].
/// When a lookup finds the cached value reports `is_expired() == true`, the cached value is
Comment thread tests/cached.rs
@@ -3149,9 +3959,6 @@ fn test_expiring_lru_cache_get_does_not_inflate_inner_metrics() {
assert!(cache.cache_get(&1).is_some());
assert_eq!(cache.cache_hits(), Some(1));
assert_eq!(cache.cache_misses(), Some(0));
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.

2 participants