defmodule EslHn do @moduledoc """ EslHn keeps the contexts that define your domain and business logic. Contexts are also responsible for managing your data, regardless if it comes from the database, an external API or others. """ alias EslHn.Cache def all(page \\ 1, per_page \\ 10) do skip = per_page * (page - 1) ids = Cache.get(EslHn, :index, []) ids |> Enum.drop(skip) |> Enum.take(per_page) |> Enum.map(&Cache.get(EslHn, &1)) end def story(id) do Cache.fetch(EslHn, id) end def broadcast_new(stories) do Phoenix.PubSub.broadcast(EslHn.PubSub, "hn:new", {:new_stories, stories}) end def subscribe_new do Phoenix.PubSub.subscribe(EslHn.PubSub, "hn:new") end end