DnsCache
struct DnsCacheA TTL-bounded resolution cache over the sync resolver.
Fields are owned by the caller; the cache mutates through mut self (no interior mutability), so it composes anywhere the caller
already holds it mutably (a client's dial path, a worker loop).
Implements Movable
__init__
def __init__(out self, ttl_ms: Int = Int(30000), max_entries: Int = Int(1024)) Create a cache with the given per-entry TTL in milliseconds (default 30 s) holding at most max_entries hosts. ttl_ms <= 0 makes every entry immediately stale (every lookup re-resolves). The bound is new: a process that looked up many distinct names grew the cache without limit.
resolve
def resolve(mut self, host: String) -> List[IpAddr] Return the addresses for host, served from cache when a fresh entry exists, else re-resolved (and cached) via :func:flare.dns.resolve.
Raises DnsError / AddressParseError: propagated from the underlying resolver on a miss; failures are not cached.
resolve_async
def resolve_async(mut self, host: String, cancel: Cancel) -> List[IpAddr] Cache-aware off-reactor resolve: serve a fresh entry from memory (no thread spawn), else resolve on a pool thread via :func:flare.dns.resolve_async and cache the result.
Same caching semantics as :meth:resolve; only the miss path
differs (off-thread, cancellable). Failures are not cached.
resolve_ordered
def resolve_ordered(mut self, host: String) -> List[IpAddr] Like :meth:resolve but returns the addresses in RFC 8305 happy-eyeballs connection-attempt order (interleaved IPv6/IPv4, starting with the family of the resolver's first address) so a dialer can race the families.
invalidate
def invalidate(mut self, host: String) Drop any cached entry for host (e.g. after a dial to the cached address failed). No-op if absent.
clear
def clear(mut self) Drop all cached entries.
resolve_count
def resolve_count(self) -> Int Number of underlying resolver syscalls performed so far.
hit_count
def hit_count(self) -> Int Number of lookups served from a fresh cache entry.
size
def size(self) -> Int Number of hosts currently cached (fresh or stale).