Registry
When we started our GenServer-based CacheWorker, you may recall that we used {:global, {:cache, <media_id>}} as the value for the :name option so that we could use the {:cache, <media_id>} tuple as its name. Behind the scenes, our cache processes were being registered using the :global Erlang module, which is started with every running application and serves as a single distributed process register when we have more than one node connected. At this stage, we are still running a single node, thus, as far as we can tell, we could be using Registry, an Elixir process register introduced in version 1.4.
A process register lets us associate a name to a given process. Let's query the :global registry after spawning two cache workers:
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access