nesquena/rabl — pull request #417 by ahlatimer (2013-03-07 17:29:37+00:00)
Title: Add support for read_multi (closes #379)

With the current caching approach in rabl, each item in the cached is read separately. This can have serious performance implications when the cache is accessed over a network. Fortunately, many caching libraries implement a `read_multi` method that can fetch multiple keys simultaneously. This pull requests adds `read_multi` support to rabl.

The way rabl was previously architected, there was no way to determine what all of the cache directives were in a child element (i.e., a call to glue, child, extends, or node) without also rendering that element at the same time. That is, applying the child element to the parent view and rendering it were coupled. The child element could retrieve itself from the cache, but there was no way to apply the cache directives to all children elements and then use `read_multi` to fetch all of the keys. The majority of the changes outside the `MultiBuilder` class relate to this.

Now, instead of calling `render` on an engine, `apply` must be called first. `apply` does everything `render` did previously, short of actually rendering the template. This allows the parent engine, via the builder it constructs, to generate all the cache keys for all of the child elements. With those cache keys, we can call `read_multi`.

This was previously discussed in https://github.com/nesquena/rabl/issues/379

I realize this is a somewhat wide-reaching change, so I'm more than happy to change things as necessary to get this merged. I don't see a way of getting around the changes to `render`, however.