Getting Caching Working with Markaby

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

`method_missing': no such method `length') on line #0 of
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; return

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

        if cache = read_fragment(name, options)
          pos = buffer.length

          write_fragment(name, buffer[pos..-1],

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?


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

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

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

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.


Kevin Clark wrote: