feat(core): implement DiskCache using sled - #414
Merged
Conversation
Adds DiskCache, a CacheProvider backed by sled, a persistent, embedded, lock-free B+tree store. Values are serialized with bincode before being written to the tree, so entries survive process restarts. Blocking sled calls are offloaded to tokio::task::spawn_blocking to keep the async executor unblocked. Closes Toolbox-Lab#403
|
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 22:07
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
DiskCache, a persistent, disk-backed cache implementing theCacheProvidertrait (#412) usingsled, a high-performance embedded database. This allows large or long-lived data to be stored on the local filesystem and survive application restarts, without a custom eviction/LRU scheme.How It Was Done
crates/core/src/cache/disk.rs:DiskCachestruct wrapping anArc<sled::Db>, withnew(path)anddefault_location()constructors (the latter reuses the samedirectories::ProjectDirsconvention asCacheStore).CacheProvider::{get, put, remove, clear}: values are serialized/deserialized withbincodebefore hitting the sled tree; keys stay&str, consistent with the trait.tokio::task::spawn_blockingso the async executor is never blocked.GratError::CacheSerializationError/CacheDeserializationErrorvariants added in feat(core): implement CacheProvider trait #412; lower-level backend I/O failures (open/get/insert/remove/clear, task join errors) reuse the existingGratError::CacheError(String)variant, consistent withCacheStore.sled = "0.34"as a workspace dependency, following the same{ workspace = true }pattern asredb.flush()method (via sled's asyncflush_async) so callers needing durability guarantees (e.g. before a restart) can await it explicitly, since sled lazily batches writes.Issues Encountered (If Any)
bincodeis not self-describing, so deserializing into the wrong type doesn't reliably error unless the stored bytes are too short for the target type's layout — the type-mismatch test exploits that instead of relying on bincode detecting the mismatch directly.Related Issue
Closes #403
How It Was Tested
cargo test -p grat-core --lib cache::disk— 11/11 passing: put/get roundtrip, put overwrites existing entry, cache miss returnsOk(None), remove (present and missing key), clear, persistence across aDbclose/reopen cycle (via explicitflush()), concurrent put/get from 20 tokio tasks, and a typed deserialization-error case.cargo clippy -p grat-core --lib --tests -- -D warningsandcargo fmt --all -- --checkare clean for the new code.Screenshots / Video (If Applicable)
N/A — no UI impact.