class

Fetcher::DnsCache

Inherits Reference < Object

Process-wide DNS resolution cache.

Owns its own lock, size cap, and one-shot periodic-cleanup registration. Pure storage abstraction: the cache does not know about the caller's cache_enabled policy. Callers gate before calling (see CrestHttpClient#get_cached_dns and #cache_dns).

Constants

DEFAULT_MAX_ENTRIES = 10000

Default size cap for the cache when no explicit value is configured.

EVICTION_BUFFER = 100

Eviction buffer - remove this many entries above the configured cap in a single sweep so we don't evict on every insert at the boundary.

Class methods

clear

Drop every entry. Intended for tests and operator-driven resets.

Source
clear_expired

Drop expired entries. Invoked periodically by PeriodicCleanup.

Source
enforce_limit

Enforce max_entries + EVICTION_BUFFER. Caller must hold @@lock.

Source
ensure_cleanup_registered

Register the periodic cleanup exactly once. Public, self-locking. Safe to call from anywhere (application init, tests). Internally split from the unlocked helper because Crystal's Mutex is not re-entrant and store already holds the lock when it registers.

Source
lookup(host : String) : Socket::IPAddress | Nil

Lookup a cached address for host. Returns nil if not cached or expired. Pure read: does not mutate the cache. Expired entries remain in the cache until clear_expired removes them. PeriodicCleanup runs clear_expired on a fixed interval (60s by default) so the cache is bounded in practice.

The cache is a pure storage abstraction; enabling/disabling caching is the caller's responsibility (see CrestHttpClient#get_cached_dns).

Source
max_entries

Configure the maximum number of cache entries. Call once during app init.

Source
max_entries=(value : Int32) : Nil
Source
store(host : String, addr : Socket::IPAddress, ttl : Time::Span) : Nil

Store addr for host with the given TTL. Registers the periodic cleanup exactly once.

The cache is a pure storage abstraction; enabling/disabling caching is the caller's responsibility (see CrestHttpClient#cache_dns).

Source