Use cache for user info data.

Later these should be persisted in the user.
This commit is contained in:
Roger Braun 2017-04-30 10:04:54 +02:00
parent 8a0d2b33d8
commit ffc604a2c2
2 changed files with 6 additions and 1 deletions

View file

@ -122,4 +122,9 @@ def get_cached_by_nickname(nickname) do
key = "nickname:#{nickname}"
Cachex.get!(:user_cache, key, fallback: fn(_) -> Repo.get_by(User, nickname: nickname) end)
end
def get_cached_user_info(user) do
key = "user_info:#{user.id}"
Cachex.get!(:user_cache, key, fallback: fn(_) -> user_info(user) end)
end
end

View file

@ -11,7 +11,7 @@ def to_map(user, opts) do
false
end
user_info = User.user_info(user)
user_info = User.get_cached_user_info(user)
map = %{
"id" => user.id,