pub struct DriveCache { /* private fields */ }Expand description
Provides an HTTP cache layer backed by a SIMD R Drive data store.
§Concurrency model
- Thread-safe for concurrent access within a single process.
- Not multi-process safe for concurrent access to the same backing file.
If multiple processes need caching, use process-level coordination (e.g., external locking/ownership) or separate cache files per process.
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
Creates a new cache backed by a file-based data store.
§Arguments
cache_storage_file- Path to the file where cached responses are stored.policy- Configuration specifying cache expiration behavior.
§Concurrency
The cache is thread-safe within a process, but the backing file should not be shared for concurrent reads/writes across multiple processes.
§Panics
This function will panic if the DataStore fails to initialize.
Sourcepub fn new_process_scoped(policy: CachePolicy) -> Result<Self>
pub fn new_process_scoped(policy: CachePolicy) -> Result<Self>
Creates a new cache using discovered .cache root and a process-scoped storage bin.
The cache group is derived from this crate name (reqwest-drive), and the entry
file is created under a process/thread scoped subdirectory so callers do not need
to manually provide a cache path.
§Errors
Returns an error if discovery or process-scoped directory/file initialization fails.
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.
§Concurrency
This is thread-safe within a process. Avoid concurrent multi-process access to the same underlying store/file.
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
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
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.