pub struct DriveCache { /* private fields */ }Expand description
Provides an HTTP cache layer backed by a SIMD R Drive data store.
Implementations§
Source§impl DriveCache
impl DriveCache
Sourcepub fn new(cache_storage_file: &Path, policy: CachePolicy) -> Self
pub fn new(cache_storage_file: &Path, policy: CachePolicy) -> Self
Sourcepub fn with_drive_arc(store: Arc<DataStore>, policy: CachePolicy) -> Self
pub fn with_drive_arc(store: Arc<DataStore>, policy: CachePolicy) -> Self
Creates a new cache using an existing Arc<DataStore>.
This allows sharing the cache store across multiple components.
§Arguments
store- A sharedArc<DataStore>instance.policy- Cache expiration configuration.
Sourcepub async fn is_cached(&self, req: &Request) -> bool
pub async fn is_cached(&self, req: &Request) -> bool
Checks whether a request is cached and still valid.
This method retrieves the cache entry associated with the request and determines if it is still within its valid TTL.
§Arguments
req- The HTTP request to check for a cached response.
§Returns
Returns true if the request has a valid cached response; otherwise, false.
Trait Implementations§
Source§impl Clone for DriveCache
impl Clone for DriveCache
Source§fn clone(&self) -> DriveCache
fn clone(&self) -> DriveCache
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Middleware for DriveCache
impl Middleware for DriveCache
Source§fn handle<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
req: Request,
extensions: &'life1 mut Extensions,
next: Next<'life2>,
) -> Pin<Box<dyn Future<Output = Result<Response>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn handle<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
req: Request,
extensions: &'life1 mut Extensions,
next: Next<'life2>,
) -> Pin<Box<dyn Future<Output = Result<Response>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Intercepts HTTP requests to apply caching behavior.
This method first checks if a valid cached response exists for the incoming request.
- If a cached response is found and still valid, it is returned immediately.
- If no cache entry exists, the request is forwarded to the next middleware or backend.
- If a response is received, it is cached according to the defined
CachePolicy.
This middleware only caches GET and HEAD requests. Other HTTP methods are passed through without caching.
§Arguments
req- The incoming HTTP request.extensions- A mutable reference to request extensions, which may store metadata.next- The next middleware in the processing chain.
§Returns
A Result<Response, reqwest_middleware::Error> that contains either:
- A cached response (if available).
- A fresh response from the backend, which is then cached (if applicable).
§Behavior
- If the request is already cached and valid, returns the cached response.
- If no cache is found, the request is sent to the backend, and the response is cached.
- If the cache has expired, the old entry is deleted, and a fresh request is made.
Auto Trait Implementations§
impl Freeze for DriveCache
impl RefUnwindSafe for DriveCache
impl Send for DriveCache
impl Sync for DriveCache
impl Unpin for DriveCache
impl UnwindSafe for DriveCache
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