aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorArthur Nogueira Neves <arthurnn@gmail.com>2015-02-15 12:17:19 -0500
committerArthur Nogueira Neves <arthurnn@gmail.com>2015-02-15 12:17:19 -0500
commite825042c981e0f1cec0f45b09c2da0c1e30e607a (patch)
tree0bdcac3de0ed72f7f69b4fe46cd1cadcfecfc960 /actionpack/lib
parent66a30dc3225589d8aba6c10fee7bfa68da444e49 (diff)
parent2ed39424dbecf1d040b15d1450f0265b35b78022 (diff)
downloadrails-e825042c981e0f1cec0f45b09c2da0c1e30e607a.tar.gz
rails-e825042c981e0f1cec0f45b09c2da0c1e30e607a.tar.bz2
rails-e825042c981e0f1cec0f45b09c2da0c1e30e607a.zip
Merge pull request #18394 from arthurnn/http_cache_forever
Implement http_cache_forever to ActionController
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_controller/metal/conditional_get.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/metal/conditional_get.rb b/actionpack/lib/action_controller/metal/conditional_get.rb
index 28f0b6e349..bc6d336e19 100644
--- a/actionpack/lib/action_controller/metal/conditional_get.rb
+++ b/actionpack/lib/action_controller/metal/conditional_get.rb
@@ -215,6 +215,24 @@ module ActionController
response.cache_control.replace(:no_cache => true)
end
+ # Cache or yield the block. The cache is suppose to never expire.
+ #
+ # You can use this method when you have a HTTP response that never changes,
+ # and the browser and proxies should cache it indefinitely.
+ #
+ # <tt>public</tt> By default, HTTP responses are private, cached only on the
+ # user's web browser. To allow proxies to cache the response, set +true+ to
+ # indicate that they can serve the cached response to all users.
+ #
+ # <tt>version</tt> is the version passed as a key for the cache.
+ def http_cache_forever(public: false, version: 'v1')
+ expires_in 100.years, public: public
+
+ yield if stale?(etag: "#{version}-#{request.fullpath}",
+ last_modified: Time.parse('2011-01-01').utc,
+ public: public)
+ end
+
private
def combine_etags(options)
etags = etaggers.map { |etagger| instance_exec(options, &etagger) }.compact