Skip to content
This repository
Browse code

in caching guide, RESTifies some examples, revised conventions here a…

…nd there
  • Loading branch information...
commit 2e601d8da7cdd0712526dbf1c1346f6e19830538 1 parent e4ea27f
Xavier Noria authored
49  railties/guides/source/caching_with_rails.textile
Source Rendered
@@ -42,7 +42,7 @@ the webserver is literally just serving a file from the filesystem, cache
42 42
 expiration is an issue that needs to be dealt with.
43 43
 
44 44
 So, how do you enable this super-fast cache behavior?  Simple, let's say you
45  
-have a controller called ProductsController and a 'list' action that lists all
  45
+have a controller called +ProductsController+ and a +list+ action that lists all
46 46
 the products
47 47
 
48 48
 <ruby>
@@ -57,15 +57,15 @@ class ProductsController < ActionController
57 57
 end
58 58
 </ruby>
59 59
 
60  
-The first time anyone requests products/index, Rails will generate a file
61  
-called +index.html+ and the webserver will then look for that file before it
62  
-passes the next request for products/index to your Rails application.
  60
+The first time anyone requests +/products+, Rails will generate a file
  61
+called +products.html+ and the webserver will then look for that file before it
  62
+passes the next request for +/products+ to your Rails application.
63 63
 
64  
-By default, the page cache directory is set to Rails.public_path (which is
65  
-usually set to "#{RAILS_ROOT}/public" and this can be configured by
  64
+By default, the page cache directory is set to +Rails.public_path+ (which is
  65
+usually set to the +public+ folder) and this can be configured by
66 66
 changing the configuration setting +config.action_controller.page_cache_directory+.
67  
-Changing the default from /public helps avoid naming conflicts, since you may
68  
-want to put other static html in /public, but changing this will require web
  67
+Changing the default from +public+ helps avoid naming conflicts, since you may
  68
+want to put other static html in +public+, but changing this will require web
69 69
 server reconfiguration to let the web server know where to serve the cached
70 70
 files from.
71 71
 
@@ -96,7 +96,7 @@ end
96 96
 If you want a more complicated expiration scheme, you can use cache sweepers
97 97
 to expire cached objects when things change. This is covered in the section on Sweepers.
98 98
 
99  
-Note: Page caching ignores all parameters, so /products/list?page=1 will be written out to the filesystem as /products/list.html and if someone requests /products/list?page=2, they will be returned the same result as page=1, so be careful when page caching GET parameters in the URL!
  99
+Note: Page caching ignores all parameters. For example +/products?page=1+ will be written out to the filesystem as +products.html+ with no reference to the +page+ parameter. Thus, if someone requests +/products?page=2+ later, they will get the cached first page. Be careful when page caching GET parameters in the URL!
100 100
 
101 101
 h4. Action Caching
102 102
 
@@ -110,7 +110,7 @@ result of the output from a cached copy.
110 110
 
111 111
 Clearing the cache works in the exact same way as with Page Caching.
112 112
 
113  
-Let's say you only wanted authenticated users to call actions on the Products controller.
  113
+Let's say you only wanted authenticated users to call actions on +ProductsController+.
114 114
 
115 115
 <ruby>
116 116
 class ProductsController < ActionController
@@ -136,12 +136,12 @@ or the number of items in the cart can be left uncached. This feature is
136 136
 available as of Rails 2.2.
137 137
 
138 138
 You can modify the default action cache path by passing a +:cache_path+ option.
139  
-This will be passed directly to ActionCachePath.path_for.  This is handy for
  139
+This will be passed directly to +ActionCachePath.path_for+.  This is handy for
140 140
 actions with multiple possible routes that should be cached differently.  If
141 141
 a block is given, it is called with the current controller instance.  
142 142
 
143 143
 Finally, if you are using memcached, you can also pass +:expires_in+. In fact,
144  
-all parameters not used by caches_action are sent to the underlying cache
  144
+all parameters not used by +caches_action+ are sent to the underlying cache
145 145
 store. 
146 146
 
147 147
 h4. Fragment Caching
@@ -419,15 +419,14 @@ ActionController::Base.cache_store = :compressed_mem_cache_store, "localhost"
419 419
 ActionController::Base.cache_store = MyOwnStore.new("parameter")
420 420
 </ruby>
421 421
 
422  
-+Note: config.cache_store can be used in place of
423  
-ActionController::Base.cache_store in your Rails::Initializer.run block in
424  
-environment.rb+
  422
++Note: +config.cache_store+ can be used in place of
  423
++ActionController::Base.cache_store+ in your +Rails::Initializer.run+ block in
  424
++environment.rb+
425 425
 
426  
-In addition to all of this, Rails also adds the ActiveRecord::Base#cache_key
427  
-method that generates a key using the class name, id and updated_at timestamp
428  
-(if available).
  426
+In addition to all of this, Rails also adds the +ActiveRecord::Base#cache_key+
  427
+method that generates a key using the class name, +id+ and +updated_at+ timestamp (if available).
429 428
 
430  
-You can access these cache stores at a low level for storing queries and other objects.  Here's an example:
  429
+You can access these cache stores at a low level for storing queries and other objects. Here's an example:
431 430
 
432 431
 <ruby>
433 432
 Rails.cache.read("city")   # => nil
@@ -441,12 +440,12 @@ Conditional GETs are a feature of the HTTP specification that provide a way for
441 440
 servers to tell browsers that the response to a GET request hasn't changed
442 441
 since the last request and can be safely pulled from the browser cache.
443 442
 
444  
-They work by using the HTTP_IF_NONE_MATCH and HTTP_IF_MODIFIED_SINCE headers to
445  
-pass back and forth both a unique content identifier and the timestamp of when
446  
-the content was last changed. If the browser makes a request where the content
447  
-identifier (etag) or last modified since timestamp matches the server’s version
448  
-then the server only needs to send back an empty response with a not modified
449  
-status.
  443
+They work by using the +HTTP_IF_NONE_MATCH+ and +HTTP_IF_MODIFIED_SINCE+ headers
  444
+to pass back and forth both a unique content identifier and the timestamp of
  445
+when the content was last changed. If the browser makes a request where the
  446
+content identifier (etag) or last modified since timestamp matches the server’s
  447
+version then the server only needs to send back an empty response with a not
  448
+modified status.
450 449
 
451 450
 It is the server's (i.e. our) responsibility to look for a last modified
452 451
 timestamp and the if-none-match header and determine whether or not to send

0 notes on commit 2e601d8

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