aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/caching.rb
diff options
context:
space:
mode:
authorJamis Buck <jamis@37signals.com>2013-01-08 11:20:47 -0700
committerJamis Buck <jamis@37signals.com>2013-01-08 11:20:47 -0700
commit70e684a681352e95fb990747ef6dd7183da333a8 (patch)
tree59ea8b888d7bc9c99cdcfab3ad4bf0f346244054 /actionpack/lib/action_controller/caching.rb
parentac86cbec82acee18a5066e00b98d1c20fc677a15 (diff)
downloadrails-70e684a681352e95fb990747ef6dd7183da333a8.tar.gz
rails-70e684a681352e95fb990747ef6dd7183da333a8.tar.bz2
rails-70e684a681352e95fb990747ef6dd7183da333a8.zip
view_cache_dependency API
A declarative API for specifying dependencies that affect template cache digest computation. In your controller, specify any of said dependencies: view_cache_dependency { "phone" if using_phone? } When the block is evaluated, the resulting value is included in the cache digest calculation, allowing you to generate different digests for effectively the same template. (Mostly useful if you're mucking with template load paths.)
Diffstat (limited to 'actionpack/lib/action_controller/caching.rb')
-rw-r--r--actionpack/lib/action_controller/caching.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/caching.rb b/actionpack/lib/action_controller/caching.rb
index 2892e093af..e31743bcc7 100644
--- a/actionpack/lib/action_controller/caching.rb
+++ b/actionpack/lib/action_controller/caching.rb
@@ -70,12 +70,30 @@ module ActionController
config_accessor :perform_caching
self.perform_caching = true if perform_caching.nil?
+
+ class_attribute :_view_cache_dependencies
+ self._view_cache_dependencies = []
+ helper_method :view_cache_dependencies if respond_to?(:helper_method)
+ end
+
+ module ClassMethods
+ def view_cache_dependency(&dependency)
+ self._view_cache_dependencies += [dependency]
+ end
+
+ def view_cache_dependencies
+ _view_cache_dependencies.map { |dep| instance_exec &dep }.compact
+ end
end
def caching_allowed?
request.get? && response.status == 200
end
+ def view_cache_dependencies
+ self.class.view_cache_dependencies
+ end
+
protected
# Convenience accessor.
def cache(key, options = {}, &block)