feat(cachet): add serialization support with BincodeEncoder/BincodeCodec#377
feat(cachet): add serialization support with BincodeEncoder/BincodeCodec#377
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a serialization boundary to the cache pipeline so typed <K, V> caches can transparently encode/decode into BytesView for byte-oriented fallback tiers (e.g., Redis/Memcached), plus exposes transform-boundary promotion/refresh configuration.
Changes:
- Introduces bincode-based serialization codecs (
BincodeEncoder,BincodeCodec) and.serialize()builder methods. - Makes
TransformBuilderpromotion policy + time-to-refresh configurable (previously hardcoded). - Adds supporting traits/impls (
DistributedCacheTier,BytesView: Hash, customCacheEntry: PartialEqsemantics) and an integration test/example.
Reviewed changes
Copilot reviewed 15 out of 16 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/cachet_tier/src/lib.rs | Gates and re-exports new DistributedCacheTier under a feature flag. |
| crates/cachet_tier/src/entry.rs | Changes CacheEntry equality semantics (ignore cached_at). |
| crates/cachet_tier/src/distributed.rs | Adds marker trait for BytesView-based distributed tiers. |
| crates/cachet_tier/Cargo.toml | Adds distributed feature and optional bytesbuf dep. |
| crates/cachet/tests/serialize.rs | Adds integration test for full serialize→fallback→deserialize round-trip. |
| crates/cachet/src/transform/serialize.rs | Implements bincode encode/decode codecs targeting BytesView. |
| crates/cachet/src/transform/mod.rs | Adds/gates serialize module and internal re-exports. |
| crates/cachet/src/lib.rs | Documents serialize feature and adds module docs example; tweaks InMemoryCache cfg. |
| crates/cachet/src/builder/transform.rs | Adds configurable promotion policy + refresh settings at transform boundary. |
| crates/cachet/src/builder/serialize.rs | Adds .serialize() builder methods for cache + fallback builders. |
| crates/cachet/src/builder/mod.rs | Gates builder serialization module. |
| crates/cachet/examples/serialization.rs | Adds standalone example demonstrating serialization boundary. |
| crates/cachet/Cargo.toml | Adds serialize feature and serde/bincode/bytesbuf optional deps. |
| crates/bytesbuf/src/view.rs | Implements Hash for BytesView for hashmap key use-cases. |
| Cargo.toml | Adds workspace dependency for bincode. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #377 +/- ##
========================================
Coverage 100.0% 100.0%
========================================
Files 224 226 +2
Lines 16187 16376 +189
========================================
+ Hits 16187 16376 +189 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
afoxman
left a comment
There was a problem hiding this comment.
This all looks good to me. Maybe look at using feature gates for things like serialization in this PR, which bring in more dependencies. This could be a future task - no need to hold up this PR.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 23 out of 24 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…emove telemetry import for serialization codices
…elemetry - Codec::decode returns Result<Option<A>, Error> for soft failure support (Ok(None) = cache miss, e.g. version mismatch or corrupt data) - Prepend format version byte (0x01) on serialize encode, check on decode - Add cfg-gated tracing telemetry behind 'logs' feature for serialize/deserialize - Move serialize/transform builders into builder/ module - Consolidate PostcardCodec into serialize/codec.rs Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 22 out of 23 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…consistent imports) 2. examples/serialization.rs — "bincode" → "postcard" in doc comment 3. Cargo.toml — removed unused bincode workspace dependency
Summary
Adds a serialization boundary for the cache pipeline, enabling typed <K, V> caches to automatically serialize keys and values into
BytesView for downstream tiers (e.g., Redis, Memcached, or any byte-oriented store).
Changes
Serialization codecs (
cachet::transform::serialize)T -> BytesViewvia bincode, writing directly into pool-backedBytesBufmemoryT <-> BytesViewfor value round-trippingBuilder API
.serialize()onCacheBuilderandFallbackBuilder- applies a bincode serialization boundary, returning aTransformBuilderthat acceptsBytesView-typed fallback tierspromotion_policy()andtime_to_refresh()onTransformBuilder- previously these were hardcoded toalways()and None; now configurable at the transform boundarySupporting changes
DistributedCacheTier- new marker trait for tiers that operate on serializedBytesViewdataCacheEntryPartialEq- custom impl comparing only value + ttl (excludes cached_at), relaxed bound fromV: PartialEq + EqtoV:PartialEqBytesViewHash - required for use as cache keys in hash-map-based tiersimpl Into<CacheEntry<V>>for insert to simplify semanticsDocumentation
.serialize()builder methodexamples/serialization.rsstandalone exampleTests
Usage