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