Skip to content
This repository
Browse code

update AC::ConditionalGet documentation [ci skip]

  • Loading branch information...
commit 417aa431eb43a8ecbc7edae2d056edebf4f8792f 1 parent 191ddf2
Francesco Rodríguez frodsan authored

Showing 1 changed file with 31 additions and 27 deletions. Show diff stats Hide diff stats

  1. +31 27 actionpack/lib/action_controller/metal/conditional_get.rb
58 actionpack/lib/action_controller/metal/conditional_get.rb
@@ -18,8 +18,6 @@ module ClassMethods
18 18 # may want to add the current user id to be part of the etag to prevent authorized displaying
19 19 # of cached pages.
20 20 #
21   - # === Example
22   - #
23 21 # class InvoicesController < ApplicationController
24 22 # etag { current_user.try :id }
25 23 #
@@ -34,25 +32,28 @@ def etag(&etagger)
34 32 end
35 33 end
36 34
37   - # Sets the etag, last_modified, or both on the response and renders a
  35 + # Sets the etag, +last_modified+, or both on the response and renders a
38 36 # <tt>304 Not Modified</tt> response if the request is already fresh.
39 37 #
40   - # Parameters:
41   - # * <tt>:etag</tt>
42   - # * <tt>:last_modified</tt>
43   - # * <tt>:public</tt> By default the Cache-Control header is private, set this to true if you want your application to be cachable by other devices (proxy caches).
  38 + # === Parameters:
  39 + #
  40 + # * <tt>:etag</tt>.
  41 + # * <tt>:last_modified</tt>.
  42 + # * <tt>:public</tt> By default the Cache-Control header is private, set this to
  43 + # +true+ if you want your application to be cachable by other devices (proxy caches).
44 44 #
45   - # Example:
  45 + # === Example:
46 46 #
47 47 # def show
48 48 # @article = Article.find(params[:id])
49   - # fresh_when(:etag => @article, :last_modified => @article.created_at, :public => true)
  49 + # fresh_when(etag: @article, last_modified: @article.created_at, public: true)
50 50 # end
51 51 #
52 52 # This will render the show template if the request isn't sending a matching etag or
53 53 # If-Modified-Since header and just a <tt>304 Not Modified</tt> response if there's a match.
54 54 #
55   - # You can also just pass a record where last_modified will be set by calling updated_at and the etag by passing the object itself. Example:
  55 + # You can also just pass a record where +last_modified+ will be set by calling
  56 + # +updated_at+ and the etag by passing the object itself.
56 57 #
57 58 # def show
58 59 # @article = Article.find(params[:id])
@@ -81,22 +82,24 @@ def fresh_when(record_or_options, additional_options = {})
81 82 head :not_modified if request.fresh?(response)
82 83 end
83 84
84   - # Sets the etag and/or last_modified on the response and checks it against
  85 + # Sets the +etag+ and/or +last_modified+ on the response and checks it against
85 86 # the client request. If the request doesn't match the options provided, the
86 87 # request is considered stale and should be generated from scratch. Otherwise,
87 88 # it's fresh and we don't need to generate anything and a reply of <tt>304 Not Modified</tt> is sent.
88 89 #
89   - # Parameters:
90   - # * <tt>:etag</tt>
91   - # * <tt>:last_modified</tt>
92   - # * <tt>:public</tt> By default the Cache-Control header is private, set this to true if you want your application to be cachable by other devices (proxy caches).
  90 + # === Parameters:
  91 + #
  92 + # * <tt>:etag</tt>.
  93 + # * <tt>:last_modified</tt>.
  94 + # * <tt>:public</tt> By default the Cache-Control header is private, set this to
  95 + # +true+ if you want your application to be cachable by other devices (proxy caches).
93 96 #
94   - # Example:
  97 + # === Example:
95 98 #
96 99 # def show
97 100 # @article = Article.find(params[:id])
98 101 #
99   - # if stale?(:etag => @article, :last_modified => @article.created_at)
  102 + # if stale?(etag: @article, last_modified: @article.created_at)
100 103 # @statistics = @article.really_expensive_call
101 104 # respond_to do |format|
102 105 # # all the supported formats
@@ -104,7 +107,8 @@ def fresh_when(record_or_options, additional_options = {})
104 107 # end
105 108 # end
106 109 #
107   - # You can also just pass a record where last_modified will be set by calling updated_at and the etag by passing the object itself. Example:
  110 + # You can also just pass a record where +last_modified+ will be set by calling
  111 + # updated_at and the etag by passing the object itself.
108 112 #
109 113 # def show
110 114 # @article = Article.find(params[:id])
@@ -122,7 +126,7 @@ def fresh_when(record_or_options, additional_options = {})
122 126 # def show
123 127 # @article = Article.find(params[:id])
124 128 #
125   - # if stale?(@article, :public => true)
  129 + # if stale?(@article, public: true)
126 130 # @statistics = @article.really_expensive_call
127 131 # respond_to do |format|
128 132 # # all the supported formats
@@ -134,18 +138,18 @@ def stale?(record_or_options, additional_options = {})
134 138 !request.fresh?(response)
135 139 end
136 140
137   - # Sets a HTTP 1.1 Cache-Control header. Defaults to issuing a <tt>private</tt> instruction, so that
138   - # intermediate caches must not cache the response.
  141 + # Sets a HTTP 1.1 Cache-Control header. Defaults to issuing a +private+
  142 + # instruction, so that intermediate caches must not cache the response.
139 143 #
140 144 # expires_in 20.minutes
141   - # expires_in 3.hours, :public => true
142   - # expires_in 3.hours, :public => true, :must_revalidate => true
  145 + # expires_in 3.hours, public: true
  146 + # expires_in 3.hours, public: true, must_revalidate: true
143 147 #
144 148 # This method will overwrite an existing Cache-Control header.
145 149 # See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html for more possibilities.
146 150 #
147 151 # The method will also ensure a HTTP Date header for client compatibility.
148   - def expires_in(seconds, options = {}) #:doc:
  152 + def expires_in(seconds, options = {})
149 153 response.cache_control.merge!(
150 154 :max_age => seconds,
151 155 :public => options.delete(:public),
@@ -157,9 +161,9 @@ def expires_in(seconds, options = {}) #:doc:
157 161 response.date = Time.now unless response.date?
158 162 end
159 163
160   - # Sets a HTTP 1.1 Cache-Control header of <tt>no-cache</tt> so no caching should occur by the browser or
161   - # intermediate caches (like caching proxy servers).
162   - def expires_now #:doc:
  164 + # Sets a HTTP 1.1 Cache-Control header of <tt>no-cache</tt> so no caching should
  165 + # occur by the browser or intermediate caches (like caching proxy servers).
  166 + def expires_now
163 167 response.cache_control.replace(:no_cache => true)
164 168 end
165 169

0 comments on commit 417aa43

Please sign in to comment.
Something went wrong with that request. Please try again.