Skip to main content

CachedUrlSafety

Struct CachedUrlSafety 

Source
pub struct CachedUrlSafety { /* private fields */ }
Expand description

UrlSafety with a TTL cache in front of any implementation, honouring the provider’s own durations: an entry lives for the verdict’s UrlVerdict::cache_ttl where the provider gave one, and for Self::with_negative_ttl where it did not.

The map is bounded (the push-auth rule: no unbounded resource on an isolate) and the mutex is never held across an await — hits are served and misses staged in short critical sections around the one inner call.

Implementations§

Source§

impl CachedUrlSafety

Source

pub fn new(inner: Arc<dyn UrlSafety>, clock: Arc<dyn Clock>) -> Self

Wraps inner, holding at most DEFAULT_CACHE_CAPACITY URLs and serving a provider-silent verdict for DEFAULT_NEGATIVE_TTL.

Source

pub fn with_capacity(self, capacity: usize) -> Self

Caps the cache at capacity URLs; 0 falls back to DEFAULT_CACHE_CAPACITY — a cache that holds nothing is not a cache, and a caller who wants no caching simply does not decorate.

Past the bound, the entry that expires first is evicted: it is the one closest to needing a re-check anyway, so eviction costs one extra provider call, never correctness.

Source

pub fn with_negative_ttl(self, ttl: Duration) -> Self

Overrides the TTL applied when a verdict’s provider said nothing (UrlVerdict::cache_ttl is None).

Trait Implementations§

Source§

impl Debug for CachedUrlSafety

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Never prints a URL: the map’s contents are the checked URLs.

Source§

impl UrlSafety for CachedUrlSafety

Source§

fn check<'life0, 'life1, 'async_trait>( &'life0 self, url: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<UrlVerdict, UrlSafetyError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Checks one URL. The returned verdict’s url equals the input, verbatim. Read more
Source§

fn check_many<'life0, 'life1, 'async_trait>( &'life0 self, urls: &'life1 [String], ) -> Pin<Box<dyn Future<Output = Result<Vec<UrlVerdict>, UrlSafetyError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Checks many URLs; the results are in input order, one verdict per input. The default runs check_batch locally, then Self::check in a loop; a batch-friendly adapter overrides this with one provider call. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more