moka/common/
builder_utils.rs

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
use std::time::Duration;

#[cfg(any(feature = "sync", feature = "future"))]
use super::concurrent::housekeeper;

const YEAR_SECONDS: u64 = 365 * 24 * 3600;

pub(crate) fn ensure_expirations_or_panic(
    time_to_live: Option<Duration>,
    time_to_idle: Option<Duration>,
) {
    let max_duration = Duration::from_secs(1_000 * YEAR_SECONDS);
    if let Some(d) = time_to_live {
        assert!(d <= max_duration, "time_to_live is longer than 1000 years");
    }
    if let Some(d) = time_to_idle {
        assert!(d <= max_duration, "time_to_idle is longer than 1000 years");
    }
}

#[cfg(any(feature = "sync", feature = "future"))]
pub(crate) fn housekeeper_conf(thread_pool_enabled: bool) -> housekeeper::Configuration {
    if thread_pool_enabled {
        housekeeper::Configuration::new_thread_pool(true)
    } else {
        housekeeper::Configuration::new_blocking()
    }
}