feat: expiring ttl cache#263
Open
jaemk wants to merge 1 commit into
Open
Conversation
Merging this PR will not alter performance
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing |
3d75e50 to
df216b1
Compare
df216b1 to
9059a2b
Compare
9059a2b to
2e9a585
Compare
a4db062 to
8e250b3
Compare
8e250b3 to
7f08b62
Compare
…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]
7f08b62 to
e28bbcd
Compare
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 |
| @@ -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)); | |||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.