What I liked about this post is the usage of the Elixir and OTP standard libraries to easily replace a third-party dependency (Redis) in a personal project.
If you are going to use ETS as a cache, there are a couple of points you should keep in mind:
This is a nice demo of how to glue GenServer and an ETS table together as simply as possible, however there are better choices for a cache used in production. Check out Cachex or ConCache.
You don’t need to make a call to a process to read a from an ETS table like this. The get should just read directly from the ETS table. You’ll also want to set read_concurrency to true when creating the table.
You can also write to the ets table concurrently, but here the important one is to not send all reads from the cache through the same process.
It’s also interesting to note, that both ETS & DETS (or disk erlang term storage) is a derivative of the mnesia application. I use ETS respectfully because of this, and use mnesia 99% of the time as it’s a first class corner of OTP, whereas ETS I don’t think it was intended for anything but for a means to implement mnesia. Just food for thought.