All three of these classes contain methods that wrap around content in your templates.
BenchmarkHelper is a class you’ll mostly want to
use during development, when it may help you isolate code that’s taking the view a
long time to run.
CaptureHelper are both for
advanced development. While
allows you to specify fragments of your views that
will be stored for future reuse, and applied when the same call comes through,
CaptureHelper lets you manually grab content that needs to be
used again in the same view, probably to share content from the template with the
benchmark method takes an optional
message argument and an optional logging level
:error). It records how long the wrapped code takes to
run. It requires a block argument, so it usually looks something like:
<% benchmark "It took this long:" do %> <%= my_long_method %> <% end % >
The message and the length of time it takes to run will end up in the logs.
cache method lets you flag fragments of
your view to be kept for caching. Like
cache wraps around the view code it’s
meant to work on with a block argument:
<% cache do %> <%= my_repetitive_method_that_should_be_cached %> <% end % >
You should only cache information that doesn’t change very often, but many HTML components are pretty stable.
capture method wraps around view code and stores its output to a variable. You can ...