1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use std::sync::Arc;
use std::time::Duration;
use super::{Expiry, Store};
use crate::error::Result;
#[async_trait::async_trait]
pub trait ExpiryStore: Store + Expiry + Send + Sync {
async fn set_expiring(
&self,
scope: Arc<[u8]>,
key: Arc<[u8]>,
value: Arc<[u8]>,
expire_in: Duration,
) -> Result<()> {
self.set(scope.clone(), key.clone(), value).await?;
self.expire(scope, key, expire_in).await
}
async fn get_expiring(
&self,
scope: Arc<[u8]>,
key: Arc<[u8]>,
) -> Result<Option<(Arc<[u8]>, Option<Duration>)>> {
let val = self.get(scope.clone(), key.clone()).await?;
match val {
Some(val) => {
let expiry = self.expiry(scope, key).await?;
Ok(Some((val, expiry)))
}
None => Ok(None),
}
}
}