What's your caching strategy when using ecto?

874 views
Skip to first unread message

Alex Shneyderman

unread,
Aug 10, 2016, 7:16:52 AM8/10/16
to elixir-ecto
it is all in the subject.

Cheers,
Alex.

Ben Wilson

unread,
Aug 10, 2016, 10:00:51 PM8/10/16
to elixir-ecto
The first step in every caching strategy is figuring out if you actually need it. I've found that Ecto's pooling and Elixir's IO characteristics have shown Postgres to be much faster than my experience with rails seemed to indicate. Before caching anything make sure you actually need to.

From there it just depends on a lot of different questions. A basic :ets cache handles the vast majority of cases. Cache invalidation requirements will make some difference. Can the data change? Or is it always immutable?

Put another way, there are a variety of caching strategies because there are a variety of goals, and without some more specific goal in mind it's a bit hard to be specific.

Parker Selbert

unread,
Aug 10, 2016, 11:03:00 PM8/10/16
to elixi...@googlegroups.com
I have yet to find a situation where I need to cache the results of an Ecto query, sequence of queries, or the resulting data that is generated. With a large enough data set generating stats is sure to be expensive enough to cache, but that can be done ad-hoc using a basic :ets cache like Ben mentioned.

I've found that the values of external queries (GPS lookup, token generation) are what actually need to be generated. Those also tend to be simple, not nested or interdependent data structures, and well suited to using an Agent or simple GenServer.

— Parker

--
You received this message because you are subscribed to the Google Groups "elixir-ecto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-ecto...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ben Wilson

unread,
Aug 11, 2016, 8:56:52 AM8/11/16
to elixir-ecto
That has been my experience as well. However because Elixir can handle state so well, I've ended up choosing to model certain information via some state machine processes that are now hooked up to the UI such that they effectively form a cache. Data that comes in is written to the DB and then messaged to the process, which carries out further actions on the basis of various state logic.

Thus I got a free cache out of the deal, but without really building it for that explicit purpose.
Reply all
Reply to author
Forward
0 new messages