Add canonical route cache key derivation and tests#346
Conversation
…tically equal requests - Introduce `RouteCacheKey::for_route_request` to derive stable cache keys - Normalize route request JSON by sorting theme arrays, stable key ordering, and rounding coordinates to five decimal places - Use domain SHA-256 hashing helper to produce keys in `route:v1:<sha256>` format - Add unit tests for canonicalization logic covering sorting and rounding rules - Add Redis-backed behavioural tests ensuring equivalent requests share cache slot - Update domain exports and architecture docs to reflect canonicalization seam This enables improved cache hit rates by unifying semantically equivalent route requests under the same cache key while keeping canonicalization logic inside the domain cache-key layer, consistent with architecture guidelines. Co-authored-by: devboxerhub[bot] <devboxerhub[bot]@users.noreply.github.com>
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Reviewer's GuideImplements domain-owned canonical route cache key derivation for route requests, exposes a new derivation error type, adds unit and Redis-backed behavioural tests around canonicalization, and updates architecture/execplan docs to reflect the new cache-key seam. Class diagram for RouteCacheKey canonical derivation and errorsclassDiagram
class RouteCacheKey {
-String value
+RouteCacheKey new(String raw) Result~RouteCacheKey, RouteCacheKeyValidationError~
+RouteCacheKey for_route_request(Value payload) Result~RouteCacheKey, RouteCacheKeyDerivationError~
+&str as_str()
+String to_string()
}
class RouteCacheKeyValidationError {
<<enum>>
+InvalidNamespace
+InvalidHashLength
+InvalidCharacters
+ContainsWhitespace
}
class RouteCacheKeyDerivationError {
<<enum>>
+Hash
+Validation
}
class PayloadHashError {
<<error>>
}
class RouteRequestNormalizer {
<<utility>>
+Value normalize_route_request_value(Value value, Option~&str~ current_key)
+bool should_sort_array(Option~&str~ current_key)
+bool should_round_coordinate(Option~&str~ current_key)
+Number round_coordinate(Number number)
+const ROUTE_CACHE_NAMESPACE : &str
+const COORDINATE_PRECISION_FACTOR : f64
+const SORTED_ARRAY_KEYS : &[&str]
+const ROUNDED_COORDINATE_KEYS : &[&str]
}
class DomainHashing {
<<utility>>
+String canonicalize_and_hash(Value value) Result~String, PayloadHashError~
}
RouteCacheKey --> RouteCacheKeyValidationError : uses
RouteCacheKey --> RouteCacheKeyDerivationError : returns
RouteCacheKeyDerivationError --> RouteCacheKeyValidationError : wraps
RouteCacheKeyDerivationError --> PayloadHashError : wraps
RouteCacheKey --> RouteRequestNormalizer : uses
RouteCacheKey --> DomainHashing : uses
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Summary
Changes
Core functionality
Public API surface
Tests
Documentation
Validation notes
How to test locally
Rationale / design notes
Risks and mitigations
Progress indicators
◳ Generated by DevBoxer ◰
ℹ️ Tag @devboxerhub to ask questions and address PR feedback
📎 Task: https://www.devboxer.com/task/013b1644-7ade-47fd-a954-ba6ec8fda3ff
Summary by Sourcery
Introduce domain-owned canonical route cache key derivation for route requests and validate it with unit, integration, and documentation updates.
New Features:
Enhancements:
Documentation:
Tests: