Creating our Presence ETS table and GenServer

Let's start off with an ETS table that can store information about the various changes in Presence over the course of its lifetime. We'll need to wrap this inside of a GenServer, since we need a process that will live with our server rather than with each request (remember that ETS tables only live as long as their owner). Don't worry too much about the GenServer conventions at play here; we're going to dive into all of this in much, much more detail over the next chapter!

The important logic here will be all of the ETS-specific code! Let's start by creating a new file under lib/vocial called chat_cache.ex.

Get Phoenix Web Development 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.