Giter Site home page Giter Site logo

actionpack-page_caching's Introduction

actionpack-page_caching

Static page caching for Action Pack (removed from core in Rails 4.0).

Introduction

Page caching is an approach to caching in which response bodies are stored in files that the web server can serve directly:

  1. A request to endpoint E arrives.
  2. Its response is calculated and stored in a file F.
  3. Next time E is requested, the web server sends F directly.

That applies only to GET or HEAD requests whose response code is 200, the rest are ignored.

Unlike caching proxies or other more sophisticated setups, page caching results in a dramatic speed up while being dead simple at the same time. Awesome cost/benefit.

The reason for such performance boost is that cached endpoints are short-circuited by the web server, which is very efficient at serving static files. Requests to cached endpoints do not even reach your Rails application.

This technique, however, is only suitable for pages that do not need to go through your Rails stack, precisely. For example, content management systems like wikis have typically many pages that are a great fit for this approach, but account-based systems where people log in and manipulate their own data are often less likely candidates. As a use case you can check, Rails Contributors makes heavy use of page caching. Its source code is here.

It is not all or nothing, though, in HTML cached pages JavaScript can still tweak details here and there dynamically as a trade-off.

Installation

Add this line to your application's Gemfile:

gem "actionpack-page_caching"

And then execute:

$ bundle

Usage

Enable Caching

Page caching needs caching enabled:

config.action_controller.perform_caching = true

That goes typically in config/environments/production.rb, but you can activate that flag in any mode.

Since Rails 5 there is a special toggler to easily enable/disable caching in development mode without editing its configuration file. Just execute

$ bin/rails dev:cache

to enable/disable caching in development mode.

Configure the Cache Directory

Default Cache Directory

By default, files are stored below the public directory of your Rails application, with a path that matches the one in the URL.

For example, a page-cached request to /posts/what-is-new-in-rails-6 would be stored by default in the file public/posts/what-is-new-in-rails-6.html, and the web server would be configured to check that path in the file system before falling back to Rails. More on this later.

Custom Cache Directory

The default page caching directory can be overridden:

config.action_controller.page_cache_directory = Rails.root.join("public", "cached_pages")

There is no need to ensure the directory exists when the application boots, whenever a page has to be cached, the page cache directory is created if needed.

Custom Cache Directory per Controller

The globally configured cache directory, default or custom, can be overridden in each controller. There are three ways of doing this.

With a lambda:

class WeblogController < ApplicationController
  self.page_cache_directory = -> {
    Rails.root.join("public", request.domain)
  }
end

a symbol:

class WeblogController < ApplicationController
  self.page_cache_directory = :domain_cache_directory

  private
    def domain_cache_directory
      Rails.root.join("public", request.domain)
    end
end

or a callable object:

class DomainCacheDirectory
  def self.call(request)
    Rails.root.join("public", request.domain)
  end
end

class WeblogController < ApplicationController
  self.page_cache_directory = DomainCacheDirectory
end

Intermediate directories are created as needed also in this case.

Specify Actions to be Cached

Specifying which actions have to be cached is done through the caches_page class method:

class WeblogController < ActionController::Base
  caches_page :show, :new
end

Configure The Web Server

The wiki of the project has some examples of web server configuration.

Cache Expiration

Expiration of the cache is handled by deleting the cached files, which results in a lazy regeneration approach in which the content is stored again as cached endpoints are hit.

Full Cache Expiration

If the cache is stored in a separate directory like public/cached_pages, you can easily expire the whole thing by removing said directory.

Removing a directory recursively with something like rm -rf is unreliable because that operation is not atomic and can mess up with concurrent page cache generation.

In POSIX systems moving a file is atomic, so the recommended approach would be to move the directory first out of the way, and then recursively delete that one. Something like

#!/bin/bash

tmp=public/cached_pages-$(date +%s)
mv public/cached_pages $tmp
rm -rf $tmp

As noted before, the page cache directory is created if it does not exist, so moving the directory is enough to have a clean cache, no need to recreate.

Fine-grained Cache Expiration

The API for doing so mimics the options from url_for and friends:

class WeblogController < ActionController::Base
  def update
    List.update(params[:list][:id], params[:list])
    expire_page action: "show", id: params[:list][:id]
    redirect_to action: "show", id: params[:list][:id]
  end
end

Additionally, you can expire caches using Sweepers that act on changes in the model to determine when a cache is supposed to be expired.

Contributing

  1. Fork it.
  2. Create your feature branch (git checkout -b my-new-feature).
  3. Commit your changes (git commit -am 'Add some feature').
  4. Push to the branch (git push origin my-new-feature).
  5. Create a new Pull Request.

Code Status

  • Build Status

actionpack-page_caching's People

Contributors

claudiob avatar dhh avatar frodsan avatar fxn avatar gregmolnar avatar guilleiguaran avatar iggant avatar jackmc avatar jbampton avatar kaspth avatar mechanicles avatar michiels avatar nilbus avatar nyjt avatar parndt avatar pixeltrix avatar prathamesh-sonpatki avatar pzgz avatar rafaelfranca avatar robzolkos avatar tenderlove avatar zigomir avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

actionpack-page_caching's Issues

Rails 5 status?

I'm creating a Rails 5 JSON API, and since the cache! method is broken in jbuilder. this seems like just the thing.

I see there are existing PRs and closed issues, but is there any update on when this'll work with Rails 5?

expire_page doesn't seem to work with controller and action

The documentation makes it seem like you can do:

expire_page controller: 'home', action: 'index'

But this doesn't seem to work. The page isn't being expired.
Also, after looking through the tests, it seems only expiring a page with a custom route is tested?

expire_page '/index.html'

Is expire_fragment still working?

Hi, I'm testing here a Rails 4 app enabling caching on the development mode, but no matter what I do, fragments are not expired.

I have this code on my view at app/views/books/index.html.erb:

  <tbody>
    <% cache do %>
      <% @books.each do |book| %>
      ...
      <% end %>
    <% end %>      

And I'm using a callback on the books controller like this:

  after_action :expire_cache, only: [:update, :destroy]
  ...
    def expire_cache
      expire_fragment action: "index"
    end

When loading the page the first time, I get

Write fragment views/localhost:3001/books/ad710ad1703013e012cef8000213c386

After updating a book, I get

Expire fragment views/localhost:3001/books

But when loading the action index again, I still get

Read fragment views/localhost:3001/books/ad710ad1703013e012cef8000213c386

with the old results. I noticed the hash on the end, not used when expiring the fragment. Am I missing something?

Thanks!

New changes broke gem and it generate empty files

Hello. Looks like this commit did something bad and gem start generate empty files. After switching to:

gem 'rails', '5.0.0.1'
gem 'actionpack-page_caching', git: 'https://github.com/rails/actionpack-page_caching', ref: '3180f5ee17c4d161c4739a3f9c2e34e01d7261b7'

All start working as expected (no empty files).

multi domain issue

how to handle if we serving to multiple domain with same code and same db based on domain name,if an action is cached it show every one same page?

question: page caching with multiple domains

Hi, is it possible to use page caching with multiple domains?
I would like to write html files in filesystem like page cache does, but putting them into a folder named with the domain
Then, I would use nginx and rewrite to show these pages

Please expand on web server configuration comment

"Page caching works by configuring a web server to first check for the existence of files on disk, and to serve them directly when found, without passing the request through to Action Pack."

Could you please expand on that or perhaps link to external sources explaining how that is accomplished for some mainstream web servers like Apache?

I'd be happy to submit a pull request to embellish the documentation if somebody can point me towards where to find the information.

Thank you.

Not writing files to cache after upgrade to Rails 5.1

Have recently moved from Rails 4.2 to 5.1, have been using to cache a dynamic stylesheet successfully but is not working in rails 5.1, using actionpack 1.1.1.

I consistently get errors trying to access the stylesheet as the expected cached file is not there.
For example:

Started GET "/stylesheets/207.css" for 127.0.0.1 at 2019-03-04 15:44:52 +1100
Processing by StylesheetsController#show as CSS
  Parameters: {"id"=>"207"}
Completed 500 Internal Server Error in 29ms (ActiveRecord: 2.2ms)

ActionView::MissingTemplate - Missing template stylesheets/show, application/show with {:locale=>[:en], :formats=>[:css], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby]}. Searched in:

I am running in development, and development.rb caching section looks like:

  # Enable/disable caching. By default caching is disabled.
  if Rails.root.join('tmp/caching-dev.txt').exist?
    config.action_controller.perform_caching = true
    config.cache_store = :memory_store
    config.public_file_server.headers = {
      'Cache-Control' => "public, max-age=#{2.days.seconds.to_i}"
    }
  else
    config.action_controller.perform_caching = false
    config.cache_store = :null_store
  end

I am using "bin/rails dev:cache" to enable caching from rails guides.
my controller looks like this:

# frozen_string_literal: true

class StylesheetsController < ApplicationController
  caches_page :show, gzip: true

  def show
    @stylesheet = Stylesheet.find(params[:id])
    respond_to do |format|
      format.html
      format.css { render text: @stylesheet.contents, content_type: "text/css" }
    end
  end
end

I am expecting to see a public/stylesheets created with a file for the css but the folder is not being created.

Any ideas gratefully accepted!

No option for conditional page caching

When page caching was a part of Rails I could use a condition to determine whether or not the page was cached.

caches_page :new, unless: proc { user_signed_in? || !flash.empty? }

i.e., I only want to cache the page if no users are signed in and there are no warnings/errors/info in the flash object. However the presence of any conditional (if or unless) negates the page caching altogether.

Push to rubygems

Is it possible to get this pushed to rubygems now rails 4 is in beta?

double slashed home page url creates `.html` page cache file

The double-slashed url does not match the empty? or "/" condition here

so it is interpreted as a legit url, the trailing slash is chomped, and a file is created at /.html.

For example www.my_domain.com// will page cache to /public/cache/.html.

In testing, our NGINX setup serves this file up as an octet-stream, causing it to be downloaded instead of displayed in the browser. To make this even harder to diagnose, the file is hidden on unix-based systems because it begins with a dot.

Still going through ActionPack? am i doing it wrong?

controller

class PjController < ApplicationController
  caches_page :news, :contact, :about, :recruit, :index, :products, :acide_series, :bio, :global, :cold_rolling, :hot_rolling, :industries, :machines, :manager, :senior, :manager, :services, :strategy, :timeline
end

application.rb

require File.expand_path('../boot', __FILE__)
require 'rails/all'
Bundler.require(*Rails.groups)

module Pj
  class Application < Rails::Application
    config.time_zone = 'Beijing'
    config.i18n.default_locale = :'zh-CN'
    config.i18n.fallbacks = true
    config.action_controller.page_cache_directory = "#{Rails.root.to_s}/public/deploy"
  end
end

production.log

I, [2015-01-21T14:08:10.033309 #1266]  INFO -- : Started GET "/contact" for 222.73.202.249 at 2015-01-21 14:08:10 +0800
I, [2015-01-21T14:08:10.039919 #1266]  INFO -- : Processing by PjController#global as HTML
W, [2015-01-21T14:08:10.784323 #1266]  WARN -- : zh-TW
I, [2015-01-21T14:08:10.789743 #1266]  INFO -- :   Rendered pj/_contact_banner.html.erb (0.3ms)
I, [2015-01-21T14:08:10.790854 #1266]  INFO -- :   Rendered pj/_slider_js.html.erb (0.3ms)
I, [2015-01-21T14:08:10.791057 #1266]  INFO -- :   Rendered pj/global.zh-TW.html.erb within layouts/application (3.2ms)
I, [2015-01-21T14:08:10.794608 #1266]  INFO -- :   Rendered pj/_header.html.erb (1.1ms)
I, [2015-01-21T14:08:10.795809 #1266]  INFO -- :   Rendered pj/_footer.html.erb (0.4ms)
I, [2015-01-21T14:08:10.796650 #1266]  INFO -- : Write page /var/www/pj/releases/44/public/deploy/contact.html (0.3ms)
I, [2015-01-21T14:08:10.796939 #1266]  INFO -- : Completed 200 OK in 757ms (Views: 11.2ms | ActiveRecord: 0.0ms)
I, [2015-01-21T14:08:10.935224 #1266]  INFO -- : Started GET "/assets/logo.png" for 222.73.202.249 at 2015-01-21 14:08:10 +0800
I, [2015-01-21T14:08:10.979164 #1266]  INFO -- : Started GET "/assets/5-1.jpg" for 222.73.202.249 at 2015-01-21 14:08:10 +0800
I, [2015-01-21T14:08:10.980454 #857]  INFO -- : Started GET "/assets/alibaba-logo.png" for 222.73.202.249 at 2015-01-21 14:08:10 +0800
I, [2015-01-21T14:08:10.981162 #847]  INFO -- : Started GET "/assets/alibaba.png" for 222.73.202.249 at 2015-01-21 14:08:10 +0800
I, [2015-01-21T14:08:11.017641 #847]  INFO -- : Started GET "/assets/5-3.jpg" for 222.73.202.249 at 2015-01-21 14:08:11 +0800
I, [2015-01-21T14:08:11.017904 #857]  INFO -- : Started GET "/assets/wx.png" for 222.73.202.249 at 2015-01-21 14:08:11 +0800
I, [2015-01-21T14:08:11.020339 #1266]  INFO -- : Started GET "/assets/wx-logo.jpg" for 222.73.202.249 at 2015-01-21 14:08:11 +0800
I, [2015-01-21T14:08:11.029397 #1266]  INFO -- : Started GET "/assets/5-4.jpg" for 222.73.202.249 at 2015-01-21 14:08:11 +0800
I, [2015-01-21T14:08:11.049045 #1266]  INFO -- : Started GET "/assets/1-5.jpg" for 222.73.202.249 at 2015-01-21 14:08:11 +0800

config.action_controller.page_cache_directory not working

config.action_controller.page_cache_directory not working in production.rb (rails 4)
/gems/actionpack-4.0.0/lib/action_controller/railtie.rb:55:in `block (3 levels) in class:Railtie': Invalid option key: page_cache_directory= (RuntimeError)

But

class ApplicationController < ActionController::Base
  include ActionController::Caching::Pages
  self.page_cache_directory = "#{Rails.root.to_s}/public/page_cache"
end

working fine

how about with locale?

For example, we have products.en.erb, products.fr.erb in app/views/home that respond to home#products in separate locale.

Caching async pages

It doesn't caching async elements.
Is there any option to cache after the render finished?

Js stimulus, i18n and cache

Hi,

I use i18n js (https://github.com/fnando/i18n-js) in a stimulus controller attach to a div in a index's page which I have set caches_page :index in the controller.

I was thinking the js would only be execute on client side so that I can have i18n working depending on the lang the client set ... but it not seems working.

May I made an error ?

Thanks.

Release notes or Changelog for new versions?

I'm working to upgrade from 1.1.1 to 1.2.1 or beyond, but I'm having trouble finding documentation of the differences in the versions. I see a couple of releases under "releases", but the latest version is 1.0.1. The CHANGELOG seems to go up to 1.1.1. I see that there are some new tags beyond 1.1.1, but would like some context around what the changes are in the different versions. Is there more info on these versions somewhere else?

Rails 5.2 Support

Is there any discussions about upgrading this to 5.2?

Currently using this gem with no sucess:

gem "actionpack-page_caching", git: "https://github.com/kord-as/actionpack-page_caching", branch: "rails5"

Cache is writing but not reading

I'm new to page caching so I'm probably doing something wrong.

In my config/environments/staging.rb file I added:

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

In my products controller I added:

caches_page :show

The static html page is generated, but each time a request comes in, it still goes through the controller, renders the views, and the writes the static html page.

Here's a top and bottom snippet of my logs:

I, [2015-05-22T20:38:23.065217 #7107]  INFO -- : Started GET "/products/1" for 104.131.133.17 at 2015-05-22 20:38:23 -0400
I, [2015-05-22T20:38:23.066890 #7107]  INFO -- : Processing by ProductsController#show as HTML
I, [2015-05-22T20:38:23.067016 #7107]  INFO -- :   Parameters: {"id"=>"1"}
D, [2015-05-22T20:38:23.070506 #7107] DEBUG -- :   Product Load (0.5ms)  SELECT  "pro

....

D, [2015-05-22T20:38:23.116643 #7107] DEBUG -- :   Customer Load (0.7ms)  SELECT  "customers".* FROM "customers" WHERE "customers"."tenant_id" = $1 AND "customers"."status" = $2 AND "customers"."id" = $3  ORDER BY "customers"."id" ASC LIMIT 1  [["tenant_id", 1], ["status", 0], ["id", 1]]
I, [2015-05-22T20:38:23.117293 #7107]  INFO -- :   Rendered shared/_main_nav.html.erb (3.3ms)
I, [2015-05-22T20:38:23.118509 #7107]  INFO -- : Write page /var/www/myapp/releases/11/public/deploy/products/1.html (0.4ms)
I, [2015-05-22T20:38:23.119214 #7107]  INFO -- : Completed 200 OK in 52ms (Views: 32.2ms | ActiveRecord: 4.8ms | Elasticsearch: 0.0ms)

Amy ideas?

page_cache_directory is not initialized or set from config

In Rails 3.2 page_cache_directory is initialized to app.config.paths["public"].first in:

https://github.com/rails/rails/blob/3-2-stable/actionpack/lib/action_controller/railtie.rb

But this doesn't seem the case in this gem. It is never given a default and the value is never copied over from config so the page_cache_directory variable is always blank.

This results in the gem trying to write pages to the root of my web server when upgrading to Rails 4.

Rails 5 Support

Will this gem be supported in Rails 5? Currently the gemspec states:

gem.add_dependency 'actionpack', '>= 4.0.0', '< 5'

which doesn't support 5.0.0.beta1

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

  spec.license = 'MIT'
  # or
  spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can imagine, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.

Not working from inside engine controller

I want to cache my http status response pages, and I use my mountable engine to generate those pages for each of my applications. The problem is that nothing gets cached. I've verified that the controller method is being executed as I actually do get the fully generated HTML response; it's just that the file isn't saved to /public. You'll note below that I attempt to log the public directory inside the page_cache_directory proc but I don't see any logs written either.

Main app:

config/application.rb: config.exceptions_app = routes


Engine:

lib/manager/engine.rb: (don't know for sure if this is what I need to require, so I tried both)

require 'actionpack/page_caching'
require 'action_controller/page_caching'

Routes:

%w(401 403 404 410 422 500).each do |code|
  get code, to: 'errors#show', as: "error_#{ code }", code: code
end

ErrorsController:

require_dependency 'manager/application_controller'
module Manager
  # Raise templated HTTP response pages
  class ErrorsController < ApplicationController
    skip_before_action :login_required
    skip_before_action :find_model

    self.page_cache_directory = -> { Rails.logger.debug Rails.root.join('public').inspect; return Rails.root.join('public') }
    caches_page :show

    def show
      render_status params[:code]
    end

    protected

    def render_status(status = 500)
      status = status.to_i
      respond_to do |format|
        format.any(:html, :shtml) do
          render "#{ status }.html", status: status
        end
      end
    rescue ActionController::UnknownFormat, ActionView::MissingTemplate
      head status: status
    end
  end
end

I also call caches_page directly in one of the main application's controller and it works. It's just from within the rails engine that it doesn't.

Page Caching - Errno::EACCES (Permission denied @ dir_s_mkdir - /api)

Hi, I'm trying to used page caching for my API app with Rails 5.2.1 and actionpack-page_caching 1.1.1,
In ApplicationController if inherit from ActionController::Base, no problem found for cache page,
But if I used ActionController::API, I got error when cache_page like this:

Errno::EACCES (Permission denied @ dir_s_mkdir - /api):
/usr/share/rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/fileutils.rb:232:in mkdir' /usr/share/rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/fileutils.rb:232:in fu_mkdir'
/usr/share/rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/fileutils.rb:210:in block (2 levels) in mkdir_p' /usr/share/rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/fileutils.rb:208:in reverse_each'
/usr/share/rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/fileutils.rb:208:in block in mkdir_p' /usr/share/rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/fileutils.rb:193:in each'
/usr/share/rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/fileutils.rb:193:in mkdir_p' /home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/actionpack-page_caching-1.1.1/lib/action_controller/caching/pages.rb:167:in write'
/home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/actionpack-page_caching-1.1.1/lib/action_controller/caching/pages.rb:80:in block in cache' /home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/actionpack-page_caching-1.1.1/lib/action_controller/caching/pages.rb:176:in block in instrument'
/home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/activesupport-5.2.1/lib/active_support/notifications.rb:168:in block in instrument' /home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/activesupport-5.2.1/lib/active_support/notifications/instrumenter.rb:23:in instrument'
/home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/activesupport-5.2.1/lib/active_support/notifications.rb:168:in instrument' /home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/actionpack-page_caching-1.1.1/lib/action_controller/caching/pages.rb:176:in instrument'
/home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/actionpack-page_caching-1.1.1/lib/action_controller/caching/pages.rb:79:in cache' /home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/actionpack-page_caching-1.1.1/lib/action_controller/caching/pages.rb:282:in cache_page'
/home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/actionpack-page_caching-1.1.1/lib/action_controller/caching/pages.rb:231:in block in caches_page' /home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/activesupport-5.2.1/lib/active_support/callbacks.rb:426:in instance_exec'
/home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/activesupport-5.2.1/lib/active_support/callbacks.rb:426:in block in make_lambda' /home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/activesupport-5.2.1/lib/active_support/callbacks.rb:236:in block in halting_and_conditional'
/home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/activesupport-5.2.1/lib/active_support/callbacks.rb:517:in block in invoke_after' /home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/activesupport-5.2.1/lib/active_support/callbacks.rb:517:in each'
/home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/activesupport-5.2.1/lib/active_support/callbacks.rb:517:in invoke_after' /home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/activesupport-5.2.1/lib/active_support/callbacks.rb:133:in run_callbacks'
/home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/actionpack-5.2.1/lib/abstract_controller/callbacks.rb:41:in process_action' /home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/actionpack-5.2.1/lib/action_controller/metal/rescue.rb:22:in process_action'
/home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/actionpack-5.2.1/lib/action_controller/metal/instrumentation.rb:34:in block in process_action' /home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/activesupport-5.2.1/lib/active_support/notifications.rb:168:in block in instrument'
/home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/activesupport-5.2.1/lib/active_support/notifications/instrumenter.rb:23:in instrument' /home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/activesupport-5.2.1/lib/active_support/notifications.rb:168:in instrument'
/home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/actionpack-5.2.1/lib/action_controller/metal/instrumentation.rb:32:in process_action' /home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/actionpack-5.2.1/lib/action_controller/metal/params_wrapper.rb:256:in process_action'
/home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/actionpack-5.2.1/lib/abstract_controller/base.rb:134:in process' /home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/actionview-5.2.1/lib/action_view/rendering.rb:32:in process'
/home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/actionpack-5.2.1/lib/action_controller/metal/live.rb:255:in block (2 levels) in process' /home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/activesupport-5.2.1/lib/active_support/dependencies/interlock.rb:42:in block in running'
/home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/activesupport-5.2.1/lib/active_support/concurrency/share_lock.rb:162:in sharing' /home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/activesupport-5.2.1/lib/active_support/dependencies/interlock.rb:41:in running'
/home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/actionpack-5.2.1/lib/action_controller/metal/live.rb:247:in block in process' /home/tia/.rvm/gems/ruby-2.5.1@api_project/gems/actionpack-5.2.1/lib/action_controller/metal/live.rb:291:in block in new_controller_thread'

In my ApplicationController:

class ApplicationController < ActionController::API
    include ActionController::RequestForgeryProtection
    include ActionController::Caching

what should I do?

Defining cache directory using domain is not working

Hi,

I'm trying to setup my cache directory like that

class PagesController < ApplicationController
  self.page_cache_directory = -> { Rails.root.join("public", request.domain) }

But it don't create a folder request.domain but write cache directly on public/ folder

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.