GtBridge.CacheReaper (gt_bridge v0.19.2)

Copy Markdown View Source

I own the named ETS table that backs all GtBridge derived-state caches and invalidate per-module entries when the module recompiles.

Cache consumers go through cached/2; I only react to %ModuleEvent{kind: :recompiled} from the EventBroker by deleting every entry tagged with the affected module.

Cache key shape places the module second so a single match-delete reaches every entry for a module regardless of the entry's :kind:

{:call_sites, mod, source_hash}
{:alias_map,  mod, source_hash}
{:functions,  mod, source_hash}

Public API

Summary

Functions

I read key from the cache table and return the stored value on hit. On miss I evaluate fun, store the result, and return it.

Returns a specification to start this module under a supervisor.

Functions

cached(key, fun)

@spec cached(term(), (-> term())) :: term()

I read key from the cache table and return the stored value on hit. On miss I evaluate fun, store the result, and return it.

Concurrent races between two processes computing the same key are benign: both produce the same value for a deterministic fun, and the second insert overwrites the first with identical data.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(_)

@spec start_link(term()) :: GenServer.on_start()