pub struct Cache<I, P> { /* private fields */ }alloc or no-atomic or std only.Expand description
Passive record cache.
Implementations§
Source§impl<I, P> Cache<I, P>
impl<I, P> Cache<I, P>
Sourcepub fn with_max_entries(max: usize) -> Self
pub fn with_max_entries(max: usize) -> Self
Empty cache with a custom maximum entry cap.
When try_insert is called and the number of stored entries has reached
max, the soonest-expiring entry is evicted proactively before the new
entry is inserted. This bounds memory usage even when the backing
Pool grows without error (e.g. slab::Slab).
Sourcepub const fn max_entries(&self) -> usize
pub const fn max_entries(&self) -> usize
The configured maximum number of entries.
Sourcepub fn try_insert(
&mut self,
name: Name,
rtype: ResourceType,
rclass: ResourceClass,
rdata: impl Into<RdataBuf>,
ttl: Duration,
now: I,
cache_flush: bool,
) -> Result<Option<usize>, P::Error>
pub fn try_insert( &mut self, name: Name, rtype: ResourceType, rclass: ResourceClass, rdata: impl Into<RdataBuf>, ttl: Duration, now: I, cache_flush: bool, ) -> Result<Option<usize>, P::Error>
Insert (or update / remove) a record observation.
Semantics:
- If
ttl == 0, treat as “record going away” (RFC 6762 §10.1): clamp the matching(name, rtype, rclass, rdata)entry’sexpires_atto one second out (rescue window, never extending a sooner expiry) and returnOk(None)— NOT an immediate delete. - If
cache_flush == true(RFC 6762 §10.2), DEFER eviction by 1 second: clamp theexpires_atof every existing sibling matching(name, rtype, rclass)(and not the new rdata) tomin(current, now + 1s). This gives a refresh burst time to re-announce missing siblings before they disappear from the cache. - If a matching
(name, rtype, rclass, rdata)entry already exists, refresh its expiration in place and returnOk(Some(key))(deduplication). - Otherwise insert a new entry. If the pool is full, evict the soonest-expiring entry first (best-effort) then retry. If the retry still fails the error is propagated.
cache identity is (name, rtype, rclass, rdata). A non-IN
class record cannot dedupe with, evict, or count as an IN record.
Sourcepub fn sweep_expired(&mut self, now: I) -> usize
pub fn sweep_expired(&mut self, now: I) -> usize
Sweep expired entries, returning how many were removed.
Sourcepub fn next_expiration(&self) -> Option<I>
pub fn next_expiration(&self) -> Option<I>
Next deadline (soonest expiration), if any.
Sourcepub fn contains(
&self,
name: &Name,
rtype: ResourceType,
rclass: ResourceClass,
) -> bool
pub fn contains( &self, name: &Name, rtype: ResourceType, rclass: ResourceClass, ) -> bool
Look up whether the cache contains a record matching
(name, rtype, rclass). class is part of the cache key.
Sourcepub fn count_matching(
&self,
name: &Name,
rtype: ResourceType,
rclass: ResourceClass,
) -> usize
pub fn count_matching( &self, name: &Name, rtype: ResourceType, rclass: ResourceClass, ) -> usize
Count the number of cached entries matching (name, rtype, rclass).
Multiple distinct records can share (name, rtype, rclass) (e.g. a
multi-homed host with several A records), so a single contains
check cannot tell you whether the full RRSet landed. Use this for
RRSet-coherency checks.