This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#models/post.rb | |
class Post < ApplicationRecord | |
belongs_to :user, touch: true | |
after_save :create_json_cache | |
def self.cache_key(posts) | |
{ | |
serializer: 'posts', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
var private = "I am unreachable"; | |
} | |
// => undefined |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
var private = "I am unreachable"; | |
} | |
// => undefined |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import http from 'http'; | |
function delay(time) { | |
return new Promise(((resolve) => { | |
setTimeout(resolve, time); | |
})); | |
} | |
function serverReady() { | |
return new Promise(((resolve) => { |