rustls_acme/caches/
composite.rs

1use crate::{AccountCache, CertCache};
2use async_trait::async_trait;
3
4pub struct CompositeCache<C: CertCache + Send + Sync, A: AccountCache + Send + Sync> {
5    pub cert_cache: C,
6    pub account_cache: A,
7}
8
9impl<C: CertCache + Send + Sync, A: AccountCache + Send + Sync> CompositeCache<C, A> {
10    pub fn new(cert_cache: C, account_cache: A) -> Self {
11        Self { cert_cache, account_cache }
12    }
13    pub fn into_inner(self) -> (C, A) {
14        (self.cert_cache, self.account_cache)
15    }
16}
17
18#[async_trait]
19impl<C: CertCache + Send + Sync, A: AccountCache + Send + Sync> CertCache for CompositeCache<C, A> {
20    type EC = C::EC;
21    async fn load_cert(&self, domains: &[String], directory_url: &str) -> Result<Option<Vec<u8>>, Self::EC> {
22        self.cert_cache.load_cert(domains, directory_url).await
23    }
24
25    async fn store_cert(&self, domains: &[String], directory_url: &str, cert: &[u8]) -> Result<(), Self::EC> {
26        self.cert_cache.store_cert(domains, directory_url, cert).await
27    }
28}
29
30#[async_trait]
31impl<C: CertCache + Send + Sync, A: AccountCache + Send + Sync> AccountCache for CompositeCache<C, A> {
32    type EA = A::EA;
33    async fn load_account(&self, contact: &[String], directory_url: &str) -> Result<Option<Vec<u8>>, Self::EA> {
34        self.account_cache.load_account(contact, directory_url).await
35    }
36
37    async fn store_account(&self, contact: &[String], directory_url: &str, account: &[u8]) -> Result<(), Self::EA> {
38        self.account_cache.store_account(contact, directory_url, account).await
39    }
40}