Skip to main content

lrwf_core/cache/
options.rs

1//! Distributed cache entry options — matches ASP.NET Core's `DistributedCacheEntryOptions`.
2
3use std::time::Duration;
4
5#[derive(Debug, Clone, Default)]
6pub struct DistributedCacheEntryOptions {
7    pub absolute_expiration_relative_to_now: Option<Duration>,
8    pub sliding_expiration: Option<Duration>,
9    pub size_limit: usize,
10}
11
12impl DistributedCacheEntryOptions {
13    pub fn new() -> Self {
14        Self::default()
15    }
16
17    pub fn set_absolute_expiration_relative_to_now(mut self, d: Duration) -> Self {
18        self.absolute_expiration_relative_to_now = Some(d);
19        self
20    }
21
22    pub fn set_sliding_expiration(mut self, d: Duration) -> Self {
23        self.sliding_expiration = Some(d);
24        self
25    }
26
27    pub fn set_size_limit(mut self, bytes: usize) -> Self {
28        self.size_limit = bytes;
29        self
30    }
31}