pub struct CacheService { /* private fields */ }Implementations§
Source§impl CacheService
impl CacheService
Sourcepub fn new(config: Arc<Config>) -> Self
pub fn new(config: Arc<Config>) -> Self
Create a new cache service with the given configuration.
Note: This cannot fail - moka cache creation is infallible.
Sourcepub async fn get(&self, domain: &str) -> Option<WhoisResponse>
pub async fn get(&self, domain: &str) -> Option<WhoisResponse>
Get a cached response for a domain.
Returns Some(response) with cached=true if found, None otherwise.
Sourcepub async fn set(&self, domain: &str, response: &WhoisResponse)
pub async fn set(&self, domain: &str, response: &WhoisResponse)
Store a response in the cache.
Sourcepub async fn get_or_fetch<F, Fut>(
&self,
domain: &str,
fetch_fn: F,
) -> Result<WhoisResponse, WhoisError>
pub async fn get_or_fetch<F, Fut>( &self, domain: &str, fetch_fn: F, ) -> Result<WhoisResponse, WhoisError>
Get cached response or fetch with automatic deduplication.
If multiple concurrent requests for the same domain arrive, only ONE fetch operation will be executed. All other requests will wait for and share the same result. This prevents thundering herd problems and reduces load on WHOIS/RDAP servers.
§Arguments
domain- The domain to lookupfetch_fn- Async function that performs the actual lookup
§Returns
WhoisResponse with cached field set appropriately
Auto Trait Implementations§
impl Freeze for CacheService
impl !RefUnwindSafe for CacheService
impl Send for CacheService
impl Sync for CacheService
impl Unpin for CacheService
impl !UnwindSafe for CacheService
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