pub struct CacheLayer { /* private fields */ }Expand description
Main cache layer with three specialized caches
Implementations§
Source§impl CacheLayer
impl CacheLayer
Sourcepub fn with_config(config: CacheConfig) -> Self
pub fn with_config(config: CacheConfig) -> Self
Create a new cache layer with custom configuration
Sourcepub async fn get_or_fetch_content<F, Fut>(
&self,
url: &str,
headers: Option<&[(String, String)]>,
fetch_fn: F,
) -> Result<CachedContent, ScrapeError>
pub async fn get_or_fetch_content<F, Fut>( &self, url: &str, headers: Option<&[(String, String)]>, fetch_fn: F, ) -> Result<CachedContent, ScrapeError>
Get cached content or fetch it using the provided async function
This implements a cache-first strategy where the cache is checked first, and only if there’s a miss does it call the fetch function.
§Example
ⓘ
let content = cache.get_or_fetch_content(
"https://example.com",
None,
|| async {
// Fetch logic here
Ok(CachedContent { ... })
}
).await?;Sourcepub async fn get_or_fetch_robots<F, Fut>(
&self,
domain: &str,
fetch_fn: F,
) -> Result<CachedRobots, ScrapeError>
pub async fn get_or_fetch_robots<F, Fut>( &self, domain: &str, fetch_fn: F, ) -> Result<CachedRobots, ScrapeError>
Get cached robots.txt or fetch it
Sourcepub async fn get_or_fetch_redirect<F, Fut>(
&self,
url: &str,
fetch_fn: F,
) -> Result<Option<CachedRedirect>, ScrapeError>
pub async fn get_or_fetch_redirect<F, Fut>( &self, url: &str, fetch_fn: F, ) -> Result<Option<CachedRedirect>, ScrapeError>
Get cached redirect or fetch it
Sourcepub async fn get_metrics(&self) -> CacheMetrics
pub async fn get_metrics(&self) -> CacheMetrics
Get current cache metrics
Sourcepub async fn get_stats(&self) -> CacheStats
pub async fn get_stats(&self) -> CacheStats
Get cache statistics
Sourcepub async fn clear_content(&self)
pub async fn clear_content(&self)
Clear content cache only
Sourcepub async fn clear_robots(&self)
pub async fn clear_robots(&self)
Clear robots cache only
Sourcepub async fn clear_redirect(&self)
pub async fn clear_redirect(&self)
Clear redirect cache only
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CacheLayer
impl !RefUnwindSafe for CacheLayer
impl Send for CacheLayer
impl Sync for CacheLayer
impl Unpin for CacheLayer
impl UnsafeUnpin for CacheLayer
impl !UnwindSafe for CacheLayer
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more