Using Cachex in Phoenix - working example?

It’s already documented at:

:slight_smile:

It works fine but not very idiomatic, I’d personally do it like (well I generally have the fallback built into the cache rather than on each call, but ignoring that part):

  def get_cached_thing!(slug) do
    Cachex.get(:my_cache, slug, fallback: fn(slug) ->
        Repo.get_by!(Mything, slug: slug)
    end)
    |> case do
      {:error, _} -> nil # It's not common to return error strings, rather you'd probably want an error tuple
      {success, value} when success in [:ok, :loaded] -> value
    end
  end

Or maybe using ok/error tuples, whichever. :slight_smile: