Cache.MultiLayer.Coordinator (elixir_cache v0.5.0)

Copy Markdown View Source

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.

Summary

Functions

Notify every other node's coordinator for cache_name.

Returns a specification to start this module under a supervisor.

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

Functions

broadcast(cache_name, message)

@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(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

members(cache_name)

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

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

start_link(cache_name)