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
impl CachedUrlSafety
Sourcepub fn new(inner: Arc<dyn UrlSafety>, clock: Arc<dyn Clock>) -> Self
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.
Sourcepub fn with_capacity(self, capacity: usize) -> Self
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.
Sourcepub fn with_negative_ttl(self, ttl: Duration) -> Self
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
impl Debug for CachedUrlSafety
Source§impl UrlSafety for CachedUrlSafety
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,
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,
url equals the input,
verbatim. Read moreSource§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,
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,
check_batch locally, then
Self::check in a loop; a batch-friendly adapter overrides this
with one provider call. Read more