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:
iex> alias ElixirDrip.Storage.Supervisors.CacheSupervisor, as: Cache ElixirDrip.Storage.Supervisors.CacheSupervisor iex> Cache.put("5", "something") {:ok, #PID<0.685.0>} iex> Cache.put("7", "something else") {:ok, #PID<0.687...