macula_cache_route (macula v4.2.1)
View SourceTTL-bounded route cache for macula-net.
Phase 2 (PLAN_MACULA_NET_PHASE2.md §4.3). Replaces Phase 1's static station table in macula_route_packet: route_packet consults this cache first, falls back to macula_resolve_address on miss, and inserts the result.
Lookups are O(1) on an ETS set keyed by macula-net IPv6 address. A periodic sweep (gen_server timer) evicts entries whose expires_at has passed; lookups also expire-on-read so a stale entry never escapes.
Summary
Functions
Look up a route. Returns {ok, Entry} for a live cache hit, expired if the entry was found but past its TTL (also evicted), or miss if no entry was present.
Force a sweep right now. Useful for tests.
Types
-type lookup_result() :: {ok, route_entry()} | miss | expired.
-type route_entry() :: #{station_pubkey := <<_:256>>, host := binary(), port := 1..65535, expires_at := pos_integer()}.
Functions
-spec insert(<<_:128>>, route_entry()) -> ok.
-spec invalidate(<<_:128>>) -> ok.
-spec lookup(<<_:128>>) -> lookup_result().
Look up a route. Returns {ok, Entry} for a live cache hit, expired if the entry was found but past its TTL (also evicted), or miss if no entry was present.
-spec size() -> non_neg_integer().
-spec stop() -> ok.
-spec sweep() -> ok.
Force a sweep right now. Useful for tests.