tokio_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 {
12            cert_cache,
13            account_cache,
14        }
15    }
16    pub fn into_inner(self) -> (C, A) {
17        (self.cert_cache, self.account_cache)
18    }
19}
20
21#[async_trait]
22impl<C: CertCache + Send + Sync, A: AccountCache + Send + Sync> CertCache for CompositeCache<C, A> {
23    type EC = C::EC;
24    async fn load_cert(
25        &self,
26        domains: &[String],
27        directory_url: &str,
28    ) -> Result<Option<Vec<u8>>, Self::EC> {
29        self.cert_cache.load_cert(domains, directory_url).await
30    }
31
32    async fn store_cert(
33        &self,
34        domains: &[String],
35        directory_url: &str,
36        cert: &[u8],
37    ) -> Result<(), Self::EC> {
38        self.cert_cache
39            .store_cert(domains, directory_url, cert)
40            .await
41    }
42}
43
44#[async_trait]
45impl<C: CertCache + Send + Sync, A: AccountCache + Send + Sync> AccountCache
46    for CompositeCache<C, A>
47{
48    type EA = A::EA;
49    async fn load_account(
50        &self,
51        contact: &[String],
52        directory_url: &str,
53    ) -> Result<Option<Vec<u8>>, Self::EA> {
54        self.account_cache
55            .load_account(contact, directory_url)
56            .await
57    }
58
59    async fn store_account(
60        &self,
61        contact: &[String],
62        directory_url: &str,
63        account: &[u8],
64    ) -> Result<(), Self::EA> {
65        self.account_cache
66            .store_account(contact, directory_url, account)
67            .await
68    }
69}