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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//! Caching functionality for the Deboa HTTP client.
//!
//! This module provides the `DeboaCache` trait for implementing custom cache
//! backends. Implement this trait to provide your own caching mechanism for
//! HTTP responses.
//!
//! # Features
//!
//! - Simple key-value interface
//! - Thread-safe operations
//! - Optional TTL support (can be implemented by the concrete type)
//!
//! # Examples
//!
//! ## Implementing a custom cache
//!
//! ```no_run
//! use deboa::cache::DeboaCache;
//! use std::collections::HashMap;
//! use std::sync::{Arc, RwLock};
//!
//! #[derive(Default)]
//! struct MemoryCache {
//! store: Arc<RwLock<HashMap<String, String>>>,
//! }
//!
//! impl DeboaCache for MemoryCache {
//! fn get(&self, key: &str) -> Option<String> {
//! self.store.read().unwrap().get(key).cloned()
//! }
//!
//! fn set(&self, key: &str, value: &str) {
//! self.store.write().unwrap().insert(key.to_string(), value.to_string());
//! }
//!
//! fn delete(&self, key: &str) {
//! self.store.write().unwrap().remove(key);
//! }
//! }
//! ```
//!
//! ## Using the cache with Deboa
//!
//! ```no_run
//! # use deboa::{Deboa, cache::DeboaCache};
//! # struct MyCache;
//! # impl DeboaCache for MyCache {
//! # fn get(&self, _: &str) -> Option<String> { None }
//! # fn set(&self, _: &str, _: &str) {}
//! # fn delete(&self, _: &str) {}
//! # }
//! #
//! let cache = MyCache; // Your cache implementation
//! // let client = Deboa::builder().cache(Box::new(cache)).build();
//! ```
/// A trait defining the interface for cache implementations.
///
/// Implement this trait to provide custom caching behavior for HTTP responses.
/// The cache is responsible for storing and retrieving responses based on their
/// cache keys.
///
/// # Thread Safety
///
/// Implementations must be thread-safe as they may be accessed concurrently
/// from multiple threads.