# `Cache.MultiLayer.Coordinator`
[🔗](https://github.com/mikaak/elixir_cache/blob/main/lib/cache/multi_layer/coordinator.ex#L1)

Per-node coordinator for cross-node layer coherence in `Cache.MultiLayer`.

One coordinator runs per MultiLayer cache per node. Each joins a `:pg`
group named after the cache, so group membership doubles as a registry of
which nodes currently run the cache. When a cache is configured with
`broadcast_mode`, writes on one node notify every other member, which then
applies the change to its own node-local layers (`broadcast_layers`):

- `:invalidate` — remote nodes delete the key from their local layers; the
  next read falls through to the shared slower layer and backfills fresh.
  Message cost is the key only. Prefer this for large values or many-node
  clusters.
- `:replicate` — remote nodes write the new value into their local layers
  immediately. Costs a full value copy per member; prefer only for small
  values whose next read must not pay a fallthrough.

Delivery is best-effort (`send/2` to pg members, no acks). A member that
misses a message (netsplit, restart races) serves its stale local entry
until that entry's TTL expires — configure `backfill_ttl` (and layer TTLs)
as the correctness floor; the broadcast is only the fast path.

# `broadcast`

```elixir
@spec broadcast(atom(), tuple()) :: :ok
```

Notify every other node's coordinator for `cache_name`.

Excludes `self()`'s node's coordinator by pid so the writing node never
re-applies its own (already fresh) write.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `members`

```elixir
@spec members(atom()) :: [pid()]
```

pg-tracked coordinator pids for this cache across the cluster.

# `start_link`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
