pub struct ResponseCache { /* private fields */ }Expand description
Response cache manager
Implementations§
Source§impl ResponseCache
impl ResponseCache
Sourcepub fn new(config: CacheConfig) -> Result<Self, Error>
pub fn new(config: CacheConfig) -> Result<Self, Error>
Creates a new response cache with the given configuration
§Errors
Returns an error if the cache directory cannot be created
Sourcepub async fn store(
&self,
key: &CacheKey,
body: &str,
status_code: u16,
headers: &HashMap<String, String>,
request_info: CachedRequestInfo,
ttl: Option<Duration>,
) -> Result<(), Error>
pub async fn store( &self, key: &CacheKey, body: &str, status_code: u16, headers: &HashMap<String, String>, request_info: CachedRequestInfo, ttl: Option<Duration>, ) -> Result<(), Error>
Store a response in the cache
§Errors
Returns an error if:
- The cache file cannot be written
- JSON serialization fails
- Cache cleanup fails
Sourcepub async fn get(&self, key: &CacheKey) -> Result<Option<CachedResponse>, Error>
pub async fn get(&self, key: &CacheKey) -> Result<Option<CachedResponse>, Error>
Retrieve a response from the cache if it exists and is still valid
§Errors
Returns an error if:
- The cache file cannot be read
- JSON deserialization fails
Sourcepub async fn is_cached(&self, key: &CacheKey) -> Result<bool, Error>
pub async fn is_cached(&self, key: &CacheKey) -> Result<bool, Error>
Check if a response is cached and valid for the given key
§Errors
Returns an error if cache validation fails
Sourcepub async fn clear_api_cache(&self, api_name: &str) -> Result<usize, Error>
pub async fn clear_api_cache(&self, api_name: &str) -> Result<usize, Error>
Clear all cached responses for a specific API
§Errors
Returns an error if cache files cannot be removed
Auto Trait Implementations§
impl Freeze for ResponseCache
impl RefUnwindSafe for ResponseCache
impl Send for ResponseCache
impl Sync for ResponseCache
impl Unpin for ResponseCache
impl UnwindSafe for ResponseCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more