Skip to content

Commit 955a72c

Browse files
committed
Merge branch 'master' of github.com:lifo/docrails
Conflicts: actionpack/lib/action_view/helpers/asset_tag_helper.rb
2 parents 77fbe1c + cf3e760 commit 955a72c

36 files changed

+365
-373
lines changed

actionpack/lib/action_controller/caching.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ module ActionController #:nodoc:
2323
# Configuration examples (MemoryStore is the default):
2424
#
2525
# config.action_controller.cache_store = :memory_store
26-
# config.action_controller.cache_store = :file_store, "/path/to/cache/directory"
27-
# config.action_controller.cache_store = :mem_cache_store, "localhost"
28-
# config.action_controller.cache_store = :mem_cache_store, Memcached::Rails.new("localhost:11211")
29-
# config.action_controller.cache_store = MyOwnStore.new("parameter")
26+
# config.action_controller.cache_store = :file_store, '/path/to/cache/directory'
27+
# config.action_controller.cache_store = :mem_cache_store, 'localhost'
28+
# config.action_controller.cache_store = :mem_cache_store, Memcached::Rails.new('localhost:11211')
29+
# config.action_controller.cache_store = MyOwnStore.new('parameter')
3030
module Caching
3131
extend ActiveSupport::Concern
3232
extend ActiveSupport::Autoload
@@ -73,7 +73,7 @@ def caching_allowed?
7373
end
7474

7575
protected
76-
# Convenience accessor
76+
# Convenience accessor.
7777
def cache(key, options = {}, &block)
7878
if cache_configured?
7979
cache_store.fetch(ActiveSupport::Cache.expand_cache_key(key, :controller), options, &block)

actionpack/lib/action_controller/caching/actions.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
require 'set'
22

3-
module ActionController #:nodoc:
3+
module ActionController
44
module Caching
55
# Action caching is similar to page caching by the fact that the entire
66
# output of the response is cached, but unlike page caching, every
77
# request still goes through Action Pack. The key benefit of this is
88
# that filters run before the cache is served, which allows for
99
# authentication and other restrictions on whether someone is allowed
10-
# to execute such action. Example:
10+
# to execute such action.
1111
#
1212
# class ListsController < ApplicationController
13-
# before_filter :authenticate, :except => :public
13+
# before_filter :authenticate, except: :public
1414
#
1515
# caches_page :public
1616
# caches_action :index, :show
@@ -35,8 +35,8 @@ module Caching
3535
# <tt>http://david.example.com/lists.xml</tt>
3636
# are treated like separate requests and so are cached separately.
3737
# Keep in mind when expiring an action cache that
38-
# <tt>:action => 'lists'</tt> is not the same as
39-
# <tt>:action => 'list', :format => :xml</tt>.
38+
# <tt>action: 'lists'</tt> is not the same as
39+
# <tt>action: 'list', format: :xml</tt>.
4040
#
4141
# You can modify the default action cache path by passing a
4242
# <tt>:cache_path</tt> option. This will be passed directly to
@@ -53,18 +53,18 @@ module Caching
5353
# The following example depicts some of the points made above:
5454
#
5555
# class ListsController < ApplicationController
56-
# before_filter :authenticate, :except => :public
56+
# before_filter :authenticate, except: :public
5757
#
5858
# caches_page :public
5959
#
60-
# caches_action :index, :if => Proc.new do
60+
# caches_action :index, if: Proc.new do
6161
# !request.format.json? # cache if is not a JSON request
6262
# end
6363
#
64-
# caches_action :show, :cache_path => { :project => 1 },
65-
# :expires_in => 1.hour
64+
# caches_action :show, cache_path: { project: 1 },
65+
# expires_in: 1.hour
6666
#
67-
# caches_action :feed, :cache_path => Proc.new do
67+
# caches_action :feed, cache_path: Proc.new do
6868
# if params[:user_id]
6969
# user_list_url(http://github.com/params[:user_id,%20params[:id])
7070
# else
@@ -73,7 +73,7 @@ module Caching
7373
# end
7474
# end
7575
#
76-
# If you pass <tt>:layout => false</tt>, it will only cache your action
76+
# If you pass <tt>layout: false</tt>, it will only cache your action
7777
# content. That's useful when your layout has dynamic information.
7878
#
7979
# Warning: If the format of the request is determined by the Accept HTTP
@@ -162,9 +162,9 @@ def around(controller)
162162
class ActionCachePath
163163
attr_reader :path, :extension
164164

165-
# If +infer_extension+ is true, the cache path extension is looked up from the request's
165+
# If +infer_extension+ is +true+, the cache path extension is looked up from the request's
166166
# path and format. This is desirable when reading and writing the cache, but not when
167-
# expiring the cache - expire_action should expire the same files regardless of the
167+
# expiring the cache - +expire_action+ should expire the same files regardless of the
168168
# request format.
169169
def initialize(controller, options = {}, infer_extension = true)
170170
if infer_extension

actionpack/lib/action_controller/caching/fragments.rb

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
module ActionController #:nodoc:
1+
module ActionController
22
module Caching
3-
# Fragment caching is used for caching various blocks within
3+
# Fragment caching is used for caching various blocks within
44
# views without caching the entire action as a whole. This is
5-
# useful when certain elements of an action change frequently or
6-
# depend on complicated state while other parts rarely change or
5+
# useful when certain elements of an action change frequently or
6+
# depend on complicated state while other parts rarely change or
77
# can be shared amongst multiple parties. The caching is done using
8-
# the <tt>cache</tt> helper available in the Action View. See
8+
# the +cache+ helper available in the Action View. See
99
# ActionView::Helpers::CacheHelper for more information.
1010
#
1111
# While it's strongly recommended that you use key-based cache
1212
# expiration (see links in CacheHelper for more information),
1313
# it is also possible to manually expire caches. For example:
1414
#
15-
# expire_fragment("name_of_cache")
15+
# expire_fragment('name_of_cache')
1616
module Fragments
17-
# Given a key (as described in <tt>expire_fragment</tt>), returns
18-
# a key suitable for use in reading, writing, or expiring a
17+
# Given a key (as described in +expire_fragment+), returns
18+
# a key suitable for use in reading, writing, or expiring a
1919
# cached fragment. All keys are prefixed with <tt>views/</tt> and uses
2020
# ActiveSupport::Cache.expand_cache_key for the expansion.
2121
def fragment_cache_key(key)
2222
ActiveSupport::Cache.expand_cache_key(key.is_a?(Hash) ? url_for(key).split("://").last : key, :views)
2323
end
2424

25-
# Writes <tt>content</tt> to the location signified by
26-
# <tt>key</tt> (see <tt>expire_fragment</tt> for acceptable formats).
25+
# Writes +content+ to the location signified by
26+
# +key+ (see +expire_fragment+ for acceptable formats).
2727
def write_fragment(key, content, options = nil)
2828
return content unless cache_configured?
2929

@@ -35,8 +35,8 @@ def write_fragment(key, content, options = nil)
3535
content
3636
end
3737

38-
# Reads a cached fragment from the location signified by <tt>key</tt>
39-
# (see <tt>expire_fragment</tt> for acceptable formats).
38+
# Reads a cached fragment from the location signified by +key+
39+
# (see +expire_fragment+ for acceptable formats).
4040
def read_fragment(key, options = nil)
4141
return unless cache_configured?
4242

@@ -47,8 +47,8 @@ def read_fragment(key, options = nil)
4747
end
4848
end
4949

50-
# Check if a cached fragment from the location signified by
51-
# <tt>key</tt> exists (see <tt>expire_fragment</tt> for acceptable formats)
50+
# Check if a cached fragment from the location signified by
51+
# +key+ exists (see +expire_fragment+ for acceptable formats).
5252
def fragment_exist?(key, options = nil)
5353
return unless cache_configured?
5454
key = fragment_cache_key(key)
@@ -65,7 +65,7 @@ def fragment_exist?(key, options = nil)
6565
# * String - This would normally take the form of a path, like
6666
# <tt>pages/45/notes</tt>.
6767
# * Hash - Treated as an implicit call to +url_for+, like
68-
# <tt>{:controller => "pages", :action => "notes", :id => 45}</tt>
68+
# <tt>{ controller: 'pages', action: 'notes', id: 45}</tt>
6969
# * Regexp - Will remove any fragment that matches, so
7070
# <tt>%r{pages/\d*/notes}</tt> might remove all notes. Make sure you
7171
# don't use anchors in the regex (<tt>^</tt> or <tt>$</tt>) because
@@ -74,8 +74,8 @@ def fragment_exist?(key, options = nil)
7474
# only supported on caches that can iterate over all keys (unlike
7575
# memcached).
7676
#
77-
# +options+ is passed through to the cache store's <tt>delete</tt>
78-
# method (or <tt>delete_matched</tt>, for Regexp keys.)
77+
# +options+ is passed through to the cache store's +delete+
78+
# method (or <tt>delete_matched</tt>, for Regexp keys).
7979
def expire_fragment(key, options = nil)
8080
return unless cache_configured?
8181
key = fragment_cache_key(key) unless key.is_a?(Regexp)
@@ -89,7 +89,7 @@ def expire_fragment(key, options = nil)
8989
end
9090
end
9191

92-
def instrument_fragment_cache(name, key)
92+
def instrument_fragment_cache(name, key) # :nodoc:
9393
ActiveSupport::Notifications.instrument("#{name}.action_controller", :key => key){ yield }
9494
end
9595
end

actionpack/lib/action_controller/caching/pages.rb

Lines changed: 52 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,80 @@
11
require 'fileutils'
22
require 'active_support/core_ext/class/attribute_accessors'
33

4-
module ActionController #:nodoc:
4+
module ActionController
55
module Caching
6-
# Page caching is an approach to caching where the entire action output of is stored as a HTML file that the web server
7-
# can serve without going through Action Pack. This is the fastest way to cache your content as opposed to going dynamically
8-
# through the process of generating the content. Unfortunately, this incredible speed-up is only available to stateless pages
9-
# where all visitors are treated the same. Content management systems -- including weblogs and wikis -- have many pages that are
10-
# a great fit for this approach, but account-based systems where people log in and manipulate their own data are often less
11-
# likely candidates.
6+
# Page caching is an approach to caching where the entire action output of is
7+
# stored as a HTML file that the web server can serve without going through
8+
# Action Pack. This is the fastest way to cache your content as opposed to going
9+
# dynamically through the process of generating the content. Unfortunately, this
10+
# incredible speed-up is only available to stateless pages where all visitors are
11+
# treated the same. Content management systems -- including weblogs and wikis --
12+
# have many pages that are a great fit for this approach, but account-based systems
13+
# where people log in and manipulate their own data are often less likely candidates.
1214
#
13-
# Specifying which actions to cache is done through the <tt>caches_page</tt> class method:
15+
# Specifying which actions to cache is done through the +caches_page+ class method:
1416
#
1517
# class WeblogController < ActionController::Base
1618
# caches_page :show, :new
1719
# end
1820
#
19-
# This will generate cache files such as <tt>weblog/show/5.html</tt> and <tt>weblog/new.html</tt>, which match the URLs used
20-
# that would normally trigger dynamic page generation. Page caching works by configuring a web server to first check for the
21-
# existence of files on disk, and to serve them directly when found, without passing the request through to Action Pack.
22-
# This is much faster than handling the full dynamic request in the usual way.
21+
# This will generate cache files such as <tt>weblog/show/5.html</tt> and
22+
# <tt>weblog/new.html</tt>, which match the URLs used that would normally trigger
23+
# dynamic page generation. Page caching works by configuring a web server to first
24+
# check for the existence of files on disk, and to serve them directly when found,
25+
# without passing the request through to Action Pack. This is much faster than
26+
# handling the full dynamic request in the usual way.
2327
#
24-
# Expiration of the cache is handled by deleting the cached file, which results in a lazy regeneration approach where the cache
25-
# is not restored before another hit is made against it. The API for doing so mimics the options from +url_for+ and friends:
28+
# Expiration of the cache is handled by deleting the cached file, which results
29+
# in a lazy regeneration approach where the cache is not restored before another
30+
# hit is made against it. The API for doing so mimics the options from +url_for+ and friends:
2631
#
2732
# class WeblogController < ActionController::Base
2833
# def update
2934
# List.update(params[:list][:id], params[:list])
30-
# expire_page :action => "show", :id => params[:list][:id]
31-
# redirect_to :action => "show", :id => params[:list][:id]
35+
# expire_page action: 'show', id: params[:list][:id]
36+
# redirect_to action: 'show', id: params[:list][:id]
3237
# end
3338
# end
3439
#
35-
# Additionally, you can expire caches using Sweepers that act on changes in the model to determine when a cache is supposed to be
36-
# expired.
40+
# Additionally, you can expire caches using Sweepers that act on changes in
41+
# the model to determine when a cache is supposed to be expired.
3742
module Pages
3843
extend ActiveSupport::Concern
3944

4045
included do
41-
# The cache directory should be the document root for the web server and is set using <tt>Base.page_cache_directory = "/document/root"</tt>.
42-
# For Rails, this directory has already been set to Rails.public_path (which is usually set to <tt>Rails.root + "/public"</tt>). Changing
43-
# this setting can be useful to avoid naming conflicts with files in <tt>public/</tt>, but doing so will likely require configuring your
44-
# web server to look in the new location for cached files.
46+
# The cache directory should be the document root for the web server and is
47+
# set using <tt>Base.page_cache_directory = "/document/root"</tt>. For Rails,
48+
# this directory has already been set to Rails.public_path (which is usually
49+
# set to <tt>Rails.root + "/public"</tt>). Changing this setting can be useful
50+
# to avoid naming conflicts with files in <tt>public/</tt>, but doing so will
51+
# likely require configuring your web server to look in the new location for
52+
# cached files.
4553
class_attribute :page_cache_directory
4654
self.page_cache_directory ||= ''
4755

48-
# Most Rails requests do not have an extension, such as <tt>/weblog/new</tt>. In these cases, the page caching mechanism will add one in
49-
# order to make it easy for the cached files to be picked up properly by the web server. By default, this cache extension is <tt>.html</tt>.
50-
# If you want something else, like <tt>.php</tt> or <tt>.shtml</tt>, just set Base.page_cache_extension. In cases where a request already has an
51-
# extension, such as <tt>.xml</tt> or <tt>.rss</tt>, page caching will not add an extension. This allows it to work well with RESTful apps.
56+
# Most Rails requests do not have an extension, such as <tt>/weblog/new</tt>.
57+
# In these cases, the page caching mechanism will add one in order to make it
58+
# easy for the cached files to be picked up properly by the web server. By
59+
# default, this cache extension is <tt>.html</tt>. If you want something else,
60+
# like <tt>.php</tt> or <tt>.shtml</tt>, just set Base.page_cache_extension.
61+
# In cases where a request already has an extension, such as <tt>.xml</tt>
62+
# or <tt>.rss</tt>, page caching will not add an extension. This allows it
63+
# to work well with RESTful apps.
5264
class_attribute :page_cache_extension
5365
self.page_cache_extension ||= '.html'
5466

55-
# The compression used for gzip. If false (default), the page is not compressed.
56-
# If can be a symbol showing the ZLib compression method, for example, :best_compression
57-
# or :best_speed or an integer configuring the compression level.
67+
# The compression used for gzip. If +false+ (default), the page is not compressed.
68+
# If can be a symbol showing the ZLib compression method, for example, <tt>:best_compression</tt>
69+
# or <tt>:best_speed</tt> or an integer configuring the compression level.
5870
class_attribute :page_cache_compression
5971
self.page_cache_compression ||= false
6072
end
6173

6274
module ClassMethods
6375
# Expires the page that was cached with the +path+ as a key.
6476
#
65-
# expire_page "/lists/show"
77+
# expire_page '/lists/show'
6678
def expire_page(path)
6779
return unless perform_caching
6880
path = page_cache_path(path)
@@ -75,7 +87,7 @@ def expire_page(path)
7587

7688
# Manually cache the +content+ in the key determined by +path+.
7789
#
78-
# cache_page "I'm the cached content", "/lists/show"
90+
# cache_page "I'm the cached content", '/lists/show'
7991
def cache_page(content, path, extension = nil, gzip = Zlib::BEST_COMPRESSION)
8092
return unless perform_caching
8193
path = page_cache_path(path, extension)
@@ -90,19 +102,19 @@ def cache_page(content, path, extension = nil, gzip = Zlib::BEST_COMPRESSION)
90102
end
91103

92104
# Caches the +actions+ using the page-caching approach that'll store
93-
# the cache in a path within the page_cache_directory that
105+
# the cache in a path within the +page_cache_directory+ that
94106
# matches the triggering url.
95107
#
96-
# You can also pass a :gzip option to override the class configuration one.
108+
# You can also pass a <tt>:gzip</tt> option to override the class configuration one.
97109
#
98110
# # cache the index action
99111
# caches_page :index
100112
#
101113
# # cache the index action except for JSON requests
102-
# caches_page :index, :if => Proc.new { !request.format.json? }
114+
# caches_page :index, if: Proc.new { !request.format.json? }
103115
#
104116
# # don't gzip images
105-
# caches_page :image, :gzip => false
117+
# caches_page :image, gzip: false
106118
def caches_page(*actions)
107119
return unless perform_caching
108120
options = actions.extract_options!
@@ -144,7 +156,7 @@ def instrument_page_cache(name, path)
144156

145157
# Expires the page that was cached with the +options+ as a key.
146158
#
147-
# expire_page :controller => "lists", :action => "show"
159+
# expire_page controller: 'lists', action: 'show'
148160
def expire_page(options = {})
149161
return unless self.class.perform_caching
150162

@@ -161,10 +173,11 @@ def expire_page(options = {})
161173
end
162174
end
163175

164-
# Manually cache the +content+ in the key determined by +options+. If no content is provided, the contents of response.body is used.
165-
# If no options are provided, the url of the current request being handled is used.
176+
# Manually cache the +content+ in the key determined by +options+. If no content is provided,
177+
# the contents of response.body is used. If no options are provided, the url of the current
178+
# request being handled is used.
166179
#
167-
# cache_page "I'm the cached content", :controller => "lists", :action => "show"
180+
# cache_page "I'm the cached content", controller: 'lists', action: 'show'
168181
def cache_page(content = nil, options = nil, gzip = Zlib::BEST_COMPRESSION)
169182
return unless self.class.perform_caching && caching_allowed?
170183

0 commit comments

Comments
 (0)