aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorVipul A M <vipulnsward@gmail.com>2016-08-10 22:33:22 +0530
committerGitHub <noreply@github.com>2016-08-10 22:33:22 +0530
commita1623fc66788e46b459a8f01a8603a757aff11bf (patch)
treea424e308c95896a0f29356dc39b84719acf32dcd /guides
parent79e27b909ea983a4bec6d246ad23e77c5a2e47f4 (diff)
parent80f777e1c0276a022c7a4cb86451d234456d42b5 (diff)
downloadrails-a1623fc66788e46b459a8f01a8603a757aff11bf.tar.gz
rails-a1623fc66788e46b459a8f01a8603a757aff11bf.tar.bz2
rails-a1623fc66788e46b459a8f01a8603a757aff11bf.zip
Merge pull request #25930 from mechanicles/doc-http-cache-forever
Add documentation for `http_cache_forever`. [ci skip]
Diffstat (limited to 'guides')
-rw-r--r--guides/source/caching_with_rails.md24
1 files changed, 24 insertions, 0 deletions
diff --git a/guides/source/caching_with_rails.md b/guides/source/caching_with_rails.md
index cc84ecb216..a1b0029c47 100644
--- a/guides/source/caching_with_rails.md
+++ b/guides/source/caching_with_rails.md
@@ -512,6 +512,30 @@ class ProductsController < ApplicationController
end
```
+Sometimes we want to cache response, for example a static page, that never gets
+expired. To achieve this, we can use `http_cache_forever` helper and by doing
+so browser and proxies will cache it indefinitely.
+
+By default cached responses will be private, cached only on the user's web
+browser. To allow proxies to cache the response, set `public: true` to indicate
+that they can serve the cached response to all users.
+
+Using this helper, `last_modified` header is set to `Time.new(2011, 1, 1).utc`
+and `expires` header is set to a 100 years.
+
+WARNING: Use this method carefully as browser/proxy won't be able to invalidate
+the cached response unless browser cache is forcefully cleared.
+
+```ruby
+class HomeController < ApplicationController
+ def index
+ http_cache_forever(public: true) do
+ render
+ end
+ end
+end
+```
+
### Strong v/s Weak ETags
Rails generates weak ETags by default. Weak ETags allow semantically equivalent