Page Caching

The whole HTML page is saved to a file inside the public directory. On subsequent requests, this file is being sent directly to the user without the need to render the view and layout again.

Gemfile

[...]
gem 'actionpack-page_caching'
[...]

config/application.rb

[...]
config.action_controller.page_cache_directory = "#{Rails.root.to_s}/public/deploy"
[...]

pages_controller.rb

class PagesController < ApplicationController
  def index
  end
end

config/routes.rb

[...]
root 'pages#index'
[...]

views/pages/index.html.erb

<h1>Welcome to my Cached Site!</h1>

pages_controller.rb

class PagesController < ApplicationController
  caches_page :index
end

Boot the server and navigate to the root path. You should see the following output in the console:

Write page f:/rails/my/sitepoint/sitepoint-source/BraveCacher/public/deploy/index.html (1.0ms)

Expire caching pages_controller.rb

expire_page action: 'index'