aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source/caching_with_rails.textile
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-12-24 10:40:01 +0100
committerJosé Valim <jose.valim@gmail.com>2011-12-24 10:40:06 +0100
commit0152fe977343dc348f9a33493652b3f923e12397 (patch)
tree9aac1ae030dfc9ad9e7cef22e5d05e35011e5af1 /railties/guides/source/caching_with_rails.textile
parent7c42b9321a8c7e47304f62e9cec8ad2d9019decf (diff)
parentb4e97ea2d961c7ed99dcfa48044f4922378ff9cf (diff)
downloadrails-0152fe977343dc348f9a33493652b3f923e12397.tar.gz
rails-0152fe977343dc348f9a33493652b3f923e12397.tar.bz2
rails-0152fe977343dc348f9a33493652b3f923e12397.zip
Merge branch 'gzip-index' which contains two features:
1) Adding gzip to pages cache, closes #4124 2) Allow scaffold/model/migration generators to accept a "index" and "uniq" modifiers, as in: "tracking_id:integer:uniq" in order to generate (unique) indexes. Some types also accept custom options, for instance, you can specify the precision and scale for decimals as "price:decimal{7,2}". This feature closes #2555.
Diffstat (limited to 'railties/guides/source/caching_with_rails.textile')
-rw-r--r--railties/guides/source/caching_with_rails.textile22
1 files changed, 22 insertions, 0 deletions
diff --git a/railties/guides/source/caching_with_rails.textile b/railties/guides/source/caching_with_rails.textile
index ec9bfd4d40..0bf9ca8887 100644
--- a/railties/guides/source/caching_with_rails.textile
+++ b/railties/guides/source/caching_with_rails.textile
@@ -64,6 +64,28 @@ end
If you want a more complicated expiration scheme, you can use cache sweepers to expire cached objects when things change. This is covered in the section on Sweepers.
+By default, page caching automatically gzips file (for example, to +products.html.gz+ if user requests +/products+) to reduce size of transmitted data (web servers are typically configured to use a moderate compression ratio as a compromise, but since precompilation happens once, compression ration is maximum).
+
+Nginx is able to serve compressed content directly from disk by enabling +gzip_static+:
+
+<plain>
+location / {
+ gzip_static on; # to serve pre-gzipped version
+}
+</plain>
+
+You can disable gzipping by setting +:gzip+ option to false (for example, if action returns image):
+
+<ruby>
+ caches_page :image, :gzip => false
+</ruby>
+
+Or, you can set custom gzip compression level (level names are taken from +Zlib+ constants):
+
+<ruby>
+ caches_page :image, :gzip => :best_speed
+</ruby>
+
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. A workaround for this limitation is to include the parameters in the page's path, e.g. +/productions/page/1+.
INFO: Page caching runs in an after filter. Thus, invalid requests won't generate spurious cache entries as long as you halt them. Typically, a redirection in some before filter that checks request preconditions does the job.