-
-
Notifications
You must be signed in to change notification settings - Fork 34
refactor!: Cache instead of Arc<Cache> in public APIs
#433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Similarly to #432, this drops the `Arc` from `Arc<Cache>` in public APIs to make the interfaces more ergonomic and easier to use for the users.
Cache instead of Arc<Cache> in public APIsCache instead of Arc<Cache> in public APIs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors the caching API to improve ergonomics by removing the need for users to wrap Cache in Arc. The Cache struct now internally wraps its implementation in Arc<CacheImpl>, making it directly cloneable while maintaining the same functionality.
Key changes:
- Modified
Cacheto contain anArc<CacheImpl>wrapper around the store implementation - Updated all public APIs that previously used
Arc<Cache>to useCachedirectly - Changed internal field accesses to go through
self.inner
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| cot/src/cache.rs | Refactored Cache struct to wrap CacheImpl in Arc internally, enabling direct cloning without requiring external Arc wrapping |
| cot/src/test.rs | Updated TestRequestBuilder and TestCache to use Cache instead of Arc<Cache> in field types and return values |
| cot/src/project.rs | Changed function signatures, type aliases, and method return types throughout to use Cache directly instead of Arc<Cache> |
The refactoring is well-executed and maintains backward compatibility in functionality while improving the API ergonomics. All method implementations correctly access the inner fields through self.inner, and the change is applied consistently across all affected files.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
| Branch | arc-cache |
| Testbed | github-ubuntu-latest |
Click to view all benchmark results
| Benchmark | Latency | Benchmark Result microseconds (µs) (Result Δ%) | Upper Boundary microseconds (µs) (Limit %) |
|---|---|---|---|
| empty_router/empty_router | 📈 view plot 🚷 view threshold | 6,178.80 µs(+2.02%)Baseline: 6,056.57 µs | 6,805.38 µs (90.79%) |
| json_api/json_api | 📈 view plot 🚷 view threshold | 1,058.10 µs(+3.36%)Baseline: 1,023.70 µs | 1,132.61 µs (93.42%) |
| nested_routers/nested_routers | 📈 view plot 🚷 view threshold | 951.87 µs(+0.55%)Baseline: 946.70 µs | 1,043.58 µs (91.21%) |
| single_root_route/single_root_route | 📈 view plot 🚷 view threshold | 910.80 µs(+0.52%)Baseline: 906.13 µs | 996.11 µs (91.44%) |
| single_root_route_burst/single_root_route_burst | 📈 view plot 🚷 view threshold | 16,620.00 µs(-6.13%)Baseline: 17,705.59 µs | 20,944.96 µs (79.35%) |
| struct CacheImpl { | ||
| #[debug("..")] | ||
| store: Arc<dyn BoxCacheStore>, | ||
| store: Box<dyn BoxCacheStore>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious about this. What's the benefit of doing it this way(boxing the store in another struct and wrapping it in an Arc)?
Similarly to #432, this drops the
ArcfromArc<Cache>in public APIs to make the interfaces more ergonomic and easier to use for the users.