Skip to main content

shardline_cache/
lib.rs

1#![deny(unsafe_code)]
2#![allow(
3    clippy::missing_errors_doc,
4    clippy::missing_panics_doc,
5    clippy::missing_const_for_fn
6)]
7#![cfg_attr(
8    test,
9    allow(
10        clippy::unwrap_used,
11        clippy::expect_used,
12        clippy::indexing_slicing,
13        clippy::arithmetic_side_effects,
14        clippy::shadow_unrelated,
15        clippy::let_underscore_must_use,
16        clippy::format_push_string
17    )
18)]
19
20//! Reconstruction-cache contracts and adapters for Shardline.
21//!
22//! Reconstruction responses can be expensive to compute from large metadata
23//! indexes. This crate defines a small async cache boundary keyed by file,
24//! content hash, and optional repository scope. The in-memory adapter is useful
25//! for single-process deployments; the Redis adapter lets multiple server
26//! replicas share cached reconstruction payloads.
27//!
28//! # Example
29//!
30//! ```
31//! use shardline_cache::ReconstructionCacheKey;
32//! use shardline_protocol::{RepositoryProvider, RepositoryScope};
33//!
34//! let scope =
35//!     RepositoryScope::new(RepositoryProvider::GitHub, "acme", "assets", Some("main"))?;
36//! let latest = ReconstructionCacheKey::latest("file-123", Some(&scope));
37//! let immutable = ReconstructionCacheKey::version("file-123", "content-456", Some(&scope));
38//!
39//! assert_eq!(latest.content_hash(), None);
40//! assert_eq!(immutable.content_hash(), Some("content-456"));
41//! assert_eq!(latest.repository_scope().unwrap().provider(), "github");
42//! # Ok::<(), Box<dyn std::error::Error>>(())
43//! ```
44
45mod disabled;
46mod error;
47mod key;
48mod memory;
49mod redis;
50mod store;
51
52pub use disabled::DisabledReconstructionCache;
53pub use error::ReconstructionCacheError;
54pub use key::{ReconstructionCacheKey, RepositoryScopeCacheKey};
55pub use memory::MemoryReconstructionCache;
56pub use redis::RedisReconstructionCache;
57pub use store::{AsyncReconstructionCache, ReconstructionCacheFuture};