1#[cfg(all(feature = "cache_request", feature = "cache", not(feature = "cache_mem")))]
4use http_cache_reqwest::CACacheManager;
5
6#[cfg(all(feature = "cache_request", feature = "cache", not(feature = "cache_mem")))]
7type RequestCacheManager = CACacheManager;
8
9#[cfg(all(feature = "cache_request", feature = "cache_mem", not(feature = "cache")))]
12use http_cache_reqwest::MokaManager;
13
14#[cfg(all(feature = "cache_request", feature = "cache_mem", not(feature = "cache")))]
15type RequestCacheManager = MokaManager;
16
17#[cfg(all(feature = "cache_request", feature = "cache", feature = "cache_mem"))]
22use http_cache_reqwest::MokaManager;
23
24#[cfg(all(feature = "cache_request", feature = "cache", feature = "cache_mem"))]
25type RequestCacheManager = MokaManager;
26
27#[cfg(all(feature = "cache_request", not(feature = "cache"), not(feature = "cache_mem")))]
30use http_cache_reqwest::CACacheManager;
31
32#[cfg(all(feature = "cache_request", not(feature = "cache"), not(feature = "cache_mem")))]
33type RequestCacheManager = CACacheManager;
34
35#[cfg(all(
41 feature = "cache_request",
42 any(
43 all(feature = "cache", not(feature = "cache_mem")),
44 all(not(feature = "cache"), not(feature = "cache_mem"))
45 )
46))]
47fn make_manager() -> RequestCacheManager {
48 CACacheManager::new(
49 std::env::temp_dir().join("spider-http-cache"),
50 false,
51 )
52}
53
54#[cfg(all(
55 feature = "cache_request",
56 any(
57 feature = "cache_mem",
58 )
59))]
60fn make_manager() -> RequestCacheManager {
61 RequestCacheManager::default()
62}
63
64#[cfg(feature = "cache_request")]
65lazy_static::lazy_static! {
66 pub static ref CACACHE_MANAGER: RequestCacheManager = make_manager();
68}
69
70#[cfg(test)]
71mod tests {
72 #[cfg(all(feature = "cache_request", feature = "cache", feature = "cache_mem"))]
73 #[test]
74 fn test_both_cache_features_prefer_memory_manager() {
75 fn manager_type_name<T>(_: &T) -> &'static str {
76 std::any::type_name::<T>()
77 }
78
79 let ty = manager_type_name(&*super::CACACHE_MANAGER);
80 assert!(
81 ty.contains("MokaManager"),
82 "expected MokaManager when both cache and cache_mem are enabled, got {ty}"
83 );
84 }
85}