Skip to content

Instantly share code, notes, and snippets.

@knewter
Created March 11, 2014 05:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knewter/9479763 to your computer and use it in GitHub Desktop.
Save knewter/9479763 to your computer and use it in GitHub Desktop.
defmodule Cached do
@time_to_live 600 # 10 minutes
[:stargazers_count, :forks_count, :latest_commit_date, :description]
|> Enum.each fn(fun_name) ->
quote do
def unquote(fun_name)(repo_ident) do
:cadfaerl.get_or_fetch(:github, :"#{fun_name}#{repo_ident}", fn() ->
apply(BeamToolbox.Project.Statistics, fun_name, [repo_ident])
end, @time_to_live)
end
end
end
end
@josevalim
Copy link

defmodule Cached do
  @time_to_live 600 # 10 minutes

  [:stargazers_count, :forks_count, :latest_commit_date, :description]
  |> Enum.each fn(fun_name) ->
      def unquote(fun_name)(repo_ident) do
        fun_name = unquote(fun_name)
        :cadfaerl.get_or_fetch(:github, :"#{fun_name}#{repo_ident}", fn() ->
          apply(BeamToolbox.Project.Statistics, fun_name, [repo_ident])
        end, @time_to_live)
      end
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment