Skip to content

Instantly share code, notes, and snippets.

@jeremygottfried
Last active May 22, 2018 04:36
Show Gist options
  • Save jeremygottfried/22f15048ad2659e13eaa6b6d52239f71 to your computer and use it in GitHub Desktop.
Save jeremygottfried/22f15048ad2659e13eaa6b6d52239f71 to your computer and use it in GitHub Desktop.
#controllers/user_controller.rb
class UserController < ApplicationController
def index
users = User.includes(:posts)
json = Rails.cache.fetch(User.cache_key(users)) do
users.to_json(include: :posts)
end
render json: json
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment