feat(core): implement CacheProvider trait - #412
Merged
codeZe-us merged 1 commit intoAug 23, 2026
Conversation
Adds the shared async contract (get/put/remove/clear) that memory, disk, and Wasm-specific cache backends (Toolbox-Lab#403/Toolbox-Lab#404/Toolbox-Lab#405) will implement, so the rest of the codebase can depend on "a cache" without caring which storage mechanism backs it. - Generic over the value type (Serialize/DeserializeOwned + Send/Sync); keys stay &str, consistent with the existing CacheStore. - Methods return impl Future<..> + Send (RPITIT) rather than async fn, since a plain async fn in a trait doesn't guarantee a Send future - needed for backends that offload I/O via tokio::spawn/spawn_blocking. - Extends GratError with dedicated CacheMiss, CacheCapacityExceeded, CacheSerializationError, and CacheDeserializationError variants so backends can surface typed errors instead of ad-hoc strings. - Adds a hand-rolled in-memory conformance test double covering the trait's contract: get-after-put, overwrite, miss returns Ok(None) (not an error), remove, remove-of-missing-key, clear, and capacity overflow. Closes Toolbox-Lab#402
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
codeZe-us
self-requested a review
August 23, 2026 19:11
Contributor
|
PR reviewed |
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.
Description
Adds
CacheProvider, the shared async contract (get/put/remove/clear) that cache backends implement, so the rest of the codebase can depend on "a cache" without caring which storage mechanism backs it. This is the foundational trait that the planned memory, disk, and Wasm-specific caches (#403, #404, #405) will implement.How It Was Done
crates/core/src/cache/provider.rs:CacheProvidertrait, generic over the value type (Serialize/DeserializeOwned+Send/Sync); keys stay&str, consistent with the existingCacheStore.impl Future<..> + Send(RPITIT) rather thanasync fn. A plainasync fnin a trait doesn't guarantee the returned future isSend, and backends that offload I/O viatokio::spawn/spawn_blockingneed that guarantee — this also avoids the boxing overhead of#[async_trait].crates/core/src/error.rs: extendsGratErrorwith dedicatedCacheMiss,CacheCapacityExceeded,CacheSerializationError, andCacheDeserializationErrorvariants, so backends can surface typed errors instead of ad-hoc strings. The existingCacheError(String)variant is left as-is sinceCacheStorealready depends on it.CacheProvider, plus a trait-level test suite any future backend's own tests can mirror.Issues Encountered (If Any)
get'sVbound needed an explicitSend(not justDeserializeOwned) for the returned future to actually beSend— the value type is part of the future'sOutput, so it's included in the auto-trait computation even though it's only read after the await point.cargo build --workspace --all-targets --all-featuresfailure ingrat-wasm(rlib/dylib mismatch forwasmparser/rustls/protobuf) reproduces identically on a cleanmaincheckout, unrelated to this change.Related Issue
Closes #402
How It Was Tested
cargo test -p grat-core --lib cache::— 9/9 passing (7 new + 2 existingCacheStoretests): get-after-put, put-overwrites, miss returnsOk(None)(not an error), remove, remove-of-missing-key, clear, and over-capacity returns a typed error.cargo fmt --all -- --checkandcargo clippy -p grat-core --lib --tests -- -D warningsare clean for the new code (pre-existing clippy findings elsewhere in the crate are untouched by this PR).Screenshots / Video (If Applicable)
N/A — trait-only change, no UI impact.