Storing Presence data in ETS

We should now start writing some data to ETS since we have all of the code and support in place to handle that! We'll also want to add a ChatCache.write(...) call in any place that we had any code that dealt with modifying Phoenix Presence data! Open up lib/vocial_web/channels/chat_channel.ex, and we'll start by adding a new alias to the top of our module to make accessing our ChatCache module a little easier:

alias Vocial.ChatCache

Next, our first function in our file that deals with Presence is our handle_in function for dealing with the user_idle status message, so we'll add a single line at the top of the function to handle that:

  def handle_in("user_idle", %{"username" => username}, socket) do ChatCache.write(socket.topic, ...

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.