diff options
Diffstat (limited to 'actionpack/lib/action_view/helpers/cache_helper.rb')
-rw-r--r-- | actionpack/lib/action_view/helpers/cache_helper.rb | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/actionpack/lib/action_view/helpers/cache_helper.rb b/actionpack/lib/action_view/helpers/cache_helper.rb index d5cc14b29a..a904af56bb 100644 --- a/actionpack/lib/action_view/helpers/cache_helper.rb +++ b/actionpack/lib/action_view/helpers/cache_helper.rb @@ -32,7 +32,28 @@ module ActionView # <i>Topics listed alphabetically</i> # <% end %> def cache(name = {}, options = nil, &block) - controller.fragment_for(output_buffer, name, options, &block) + safe_concat fragment_for(name, options, &block) + nil + end + + private + # TODO: Create an object that has caching read/write on it + def fragment_for(name = {}, options = nil, &block) #:nodoc: + if controller.perform_caching + if controller.fragment_exist?(name, options) + controller.read_fragment(name, options) + else + # VIEW TODO: Make #capture usable outside of ERB + # This dance is needed because Builder can't use capture + pos = output_buffer.length + yield + fragment = output_buffer.slice!(pos..-1) + controller.write_fragment(name, fragment, options) + end + else + ret = yield + ActiveSupport::SafeBuffer.new(ret) if ret.is_a?(String) + end end end end |