Getting Caching Working with Markaby

I want to use Rails' caching when using Markaby templates, but I get errors like this:

ActionView::TemplateError (/usr/lib/ruby/gems/1.8/gems/markaby-0.5/lib/markaby/builder.rb:192:in `method_missing': no such method `length') on line #0 of app/views/items/index.mab: 1: 2: cache("#{@site.server_name}/index_items") do

Tim said:

Yep, the length error is because a lot of Rails' internals still assume ERB, which uses a different buffer structureto Markaby.

Looking at Rails' code:

      # Called by CacheHelper#cache       def cache_erb_fragment(block, name = {}, options = nil)         unless perform_caching then block.call; return end

        buffer = eval("_erbout", block.binding)

        if cache = read_fragment(name, options)           buffer.concat(cache)         else           pos = buffer.length           block.call           write_fragment(name, buffer[pos..-1], options)         end       end

It seems like Markaby might have to have a "length" attribute and/or act like "buffer"? Or would Rails need to be changed on the eval line?

Joe

Joe, This list is for the development of Rails itself. Please don't post here for things like that. There's a Rails-talk list for that.

Kevin Clark

Actually this is rails development related: fragment caching in rails does not work other than erb template types. The error being thrown is always the same since fragment caching was built specifically targeting ERB templates.

I have hit this problem when trying to fragment cache builder templates. Submitted a patch in #6642, to allow caching in Builder and Rjs templates too.

Additionally extending for other templates like Foo (*.foo) would be as simple as adding a controller method like:

def cache_foo_fragment(block, name) fragment_for(block, name, options) do    # use eval here to retrive the generated content up to now end end

For some tempate types like Markaby retrieving generated content up to a certain line is tricky.

Btw kinda strange but I dont see this patch in any patch report.

Zsombor

Kevin Clark wrote: