Implementing a CacheWorker with GenServer

We will now implement a CacheWorker process on ElixirDrip, which we'll use to keep the most recent media in memory. By using this cache mechanism, we hope to reduce the time it takes for a file to be downloaded and also avoid having to run the full download pipeline for every download handled by ElixirDrip.

Our CacheWorker will keep some content in memory for a while, associated with a specific cache key. In our case, the cache key will be the id of the media. Since we don't want to spawn more than one cache process for the same media, we will also use the media id on the process name. This way, if someone tries to cache media that already lives in the cache, it will be informed that a process with ...

Get Mastering Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.