Skip to main content

sui_cache/storage/
mod.rs

1//! Storage backend trait and implementations.
2//!
3//! The `StorageBackend` trait abstracts over where narinfo metadata and
4//! compressed NAR blobs are persisted. Three implementations are provided:
5//!
6//! - [`LocalStorage`] — local filesystem (default)
7//! - [`S3Storage`] — S3-compatible object storage (AWS, MinIO, R2, RustFS)
8//! - [`StorageIndex`] — redb ephemeral metadata index (accelerates S3 lookups)
9
10pub mod index;
11pub mod local;
12pub mod s3;
13
14pub use index::StorageIndex;
15pub use local::LocalStorage;
16pub use s3::S3Storage;
17
18use async_trait::async_trait;
19
20use crate::CacheError;
21
22/// Abstraction over binary cache storage.
23///
24/// Narinfo files are keyed by the 32-character store path hash.
25/// NAR blobs are keyed by their relative URL path (e.g. `nar/<hash>.nar.xz`).
26#[async_trait]
27pub trait StorageBackend: Send + Sync {
28    /// Retrieve narinfo text by store path hash.
29    async fn get_narinfo(&self, hash: &str) -> Result<Option<String>, CacheError>;
30
31    /// Store narinfo text keyed by store path hash.
32    async fn put_narinfo(&self, hash: &str, content: &str) -> Result<(), CacheError>;
33
34    /// Retrieve a NAR blob by its relative path.
35    async fn get_nar(&self, path: &str) -> Result<Option<Vec<u8>>, CacheError>;
36
37    /// Store a NAR blob at the given relative path.
38    async fn put_nar(&self, path: &str, data: &[u8]) -> Result<(), CacheError>;
39
40    /// Delete a store path's narinfo and associated NAR blob.
41    async fn delete(&self, hash: &str) -> Result<(), CacheError>;
42
43    /// List all stored narinfo hashes.
44    async fn list_narinfos(&self) -> Result<Vec<String>, CacheError>;
45}