intrepid_model/caches/
cache_repo.rs

1use super::{Cache, CacheRecord, IntoCache};
2
3/// An error that can occur when interacting with a cache repository.
4#[derive(Debug, thiserror::Error)]
5pub enum CacheRepoError {
6    /// Unable to insert a cache record
7    #[error("Unable to set cache record")]
8    SetFailed,
9}
10
11/// The trait for a cache repository. Implement this trait to provide a cache
12/// repository interface for any given cache implementation.
13#[async_trait::async_trait]
14pub trait CacheRepo {
15    /// Get a memo by URI
16    async fn get_memo(
17        &self,
18        uri: impl AsRef<str> + Send,
19    ) -> Result<Cache<CacheRecord>, CacheRepoError>;
20
21    /// Set a memo with any type that implements [`IntoCache`]
22    async fn set_memo<CacheCandidate>(
23        &self,
24        record: CacheCandidate,
25    ) -> Result<CacheRecord, CacheRepoError>
26    where
27        CacheCandidate: IntoCache + Send;
28}