instance method cache_page

Ruby on Rails 3.1.12

Since v2.2.3 Last seen in v3.2.22.5

Available in: v2.2.3 v2.3.18 v3.0.20 v3.1.12 v3.2.22.5

Signature

cache_page(content = nil, options = nil)

Manually cache the content in the key determined by options. If no content is provided, the contents of response.body is used If no options are provided, the requested url is used. Example:

cache_page "I'm the cached content", :controller => "lists", :action => "show"

Parameters

content opt = nil
options opt = nil
Source
# File actionpack/lib/action_controller/caching/pages.rb, line 138
      def cache_page(content = nil, options = nil)
        return unless self.class.perform_caching && caching_allowed?

        path = case options
          when Hash
            url_for(options.merge(:only_path => true, :format => params[:format]))
          when String
            options
          else
            request.path
        end

        if (type = Mime::LOOKUP[self.content_type]) && (type_symbol = type.symbol).present?
          extension = ".#{type_symbol}"
        end

        self.class.cache_page(content || response.body, path, extension)
      end

Defined in actionpack/lib/action_controller/caching/pages.rb line 138 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActionController::Caching::Pages

Type at least 2 characters to search.

↑↓ navigate · open · esc close