To help us understand how tasks work, we need a lazy cache mechanism. For this purpose, let's define a SlowCacheSupervisor process that delegates its put/2 and get/1 to the well-behaved CacheSupervisor already introduced, but before that, it sleeps for as many seconds as the media id it receives:
defmodule ElixirDrip.Storage.Supervisors.SlowCacheSupervisor do @behaviour ElixirDrip.Behaviours.CacheSupervisor alias ElixirDrip.Storage.Supervisors.CacheSupervisor, as: RealCache def put(id, content), do: RealCache.put(id, content) def get(id) do secs_to_nap = case Integer.parse(id) do {sleep_time, _} -> sleep_time _ -> 1 end Process.sleep(secs_to_nap * 1000) RealCache.get(id) end # ...end
We now want to create a parallel text search ...