diff options
author | José Valim <jose.valim@gmail.com> | 2010-10-07 21:30:19 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-10-07 21:31:31 +0200 |
commit | c7760809bfc8e19362272b71b23a294d48195d65 (patch) | |
tree | 1666edc988670ebe6ccc966a778ebae1759b7f43 /actionpack/lib/action_view/lookup_context.rb | |
parent | c563f10f3e8083bebe32200fa065748c8bcb65c9 (diff) | |
download | rails-c7760809bfc8e19362272b71b23a294d48195d65.tar.gz rails-c7760809bfc8e19362272b71b23a294d48195d65.tar.bz2 rails-c7760809bfc8e19362272b71b23a294d48195d65.zip |
Allow cache to be temporarily disabled through lookup_context.
Diffstat (limited to 'actionpack/lib/action_view/lookup_context.rb')
-rw-r--r-- | actionpack/lib/action_view/lookup_context.rb | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/actionpack/lib/action_view/lookup_context.rb b/actionpack/lib/action_view/lookup_context.rb index 794fdeae64..0cff888ac1 100644 --- a/actionpack/lib/action_view/lookup_context.rb +++ b/actionpack/lib/action_view/lookup_context.rb @@ -61,6 +61,7 @@ module ActionView def initialize(view_paths, details = {}) @details, @details_key = { :handlers => default_handlers }, nil @frozen_formats, @skip_default_locale = false, false + @cache = details.key?(:cache) ? details.delete(:cache) : true self.view_paths = view_paths self.registered_detail_setters.each do |key, setter| @@ -130,10 +131,20 @@ module ActionView end module Details + attr_accessor :cache + # Calculate the details key. Remove the handlers from calculation to improve performance # since the user cannot modify it explicitly. def details_key #:nodoc: - @details_key ||= DetailsKey.get(@details) + @details_key ||= DetailsKey.get(@details) if @cache + end + + # Temporary skip passing the details_key forward. + def disable_cache + old_value, @cache = @cache, false + yield + ensure + @cache = old_value end # Freeze the current formats in the lookup context. By freezing them, you are guaranteeing |