Permalink
Browse files

Cache pages for ⚡️ lightning speed

  • Loading branch information...
nilbus committed Sep 14, 2015
1 parent 772796f commit cba47513888c5cdea0105b334862a50ffa7a0dcb
View
@@ -10,6 +10,7 @@
/log/*
/public/system
/public/assets
/public/page_cache
/tags
/tmp/*
/config/secrets.yml
View
@@ -3,6 +3,7 @@ source "https://rubygems.org"
ruby "2.2.3"
gem "adamantium"
gem "actionpack-page_caching", "~> 1.0"
gem "airbrake"
gem "autoprefixer-rails"
gem "bourbon", "~> 4.2.0"
View
@@ -14,6 +14,8 @@ GEM
rack-test (~> 0.6.2)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionpack-page_caching (1.0.2)
actionpack (>= 4.0.0, < 5)
actionview (4.2.3)
activesupport (= 4.2.3)
builder (~> 3.1)
@@ -312,6 +314,7 @@ PLATFORMS
ruby
DEPENDENCIES
actionpack-page_caching (~> 1.0)
adamantium
airbrake
autoprefixer-rails
View
@@ -52,6 +52,10 @@ After bundler installs gems, these initial setup steps will get the app running:
rails server
* (Optional) For fast page loads, [configure your web server][1] to use the page
caches that the app generates in `public/page_cache/`.
[1]: https://github.com/rails/actionpack-page_caching/issues/27#issuecomment-110550147
Customizing
===========
@@ -1,4 +1,6 @@
class PortfoliosController < ApplicationController
caches_page :index, :show
def index
end
@@ -7,16 +9,26 @@ def show
@portfolio = PortfolioStore.new.find(@github_username)
respond_to do |format|
format.html { render :loading if @portfolio.nil? }
format.json do
@portfolio = FetchDataWorker.new(@github_username).perform
message = 'reload; portfolio serialization to json not yet supported'
render json: {result: message}
end
format.json { reload_portfolio(@github_username) }
end
end
def reload
@github_username = params[:id]
render :loading
end
private
def reload_portfolio(github_username)
@portfolio = FetchDataWorker.new(github_username).perform
expire_page_cache(github_username)
message = 'reload; portfolio serialization to json not yet supported'
render json: {result: message}
end
def expire_page_cache(github_username)
expire_page "/#{github_username}"
expire_page '/' if github_username == ENV['PORTFOLIO']
end
end
@@ -28,6 +28,8 @@
# Enable deflate / gzip compression of controller-generated responses
config.middleware.use Rack::Deflater
config.action_controller.page_cache_directory = Rails.root.join "public/page_cache"
# Ensure requests are only served from one, canonical host name
config.middleware.use Rack::CanonicalHost, ENV.fetch("HOST")
No changes.

0 comments on commit cba4751

Please sign in to comment.