Cells::Collection
Allows cell rendering for a collection of items in one go.
This allows Rails to utilize cache store's get_multi
method. When cache store supports it (e.g. Memcached), this results in only one cache read request for the whole collection.
The performance boost does vary from action to action, so always benchmark to see if it improved the performance. Two biggest boost can happen when:
- Cache store lives at a remote location.
- Collection size over 50 items.
Installation
Add this line to your application's Gemfile after cells gem declaration:
gem 'cells'
gem 'cells-collection'
And then execute:
$ bundle install
To setup Rails to use Memcached store, take look at the dalli gem.
Usage
Doing this in the view:
<%= render_cell_collection :cart, :item, @items %>
will be equivalent to the old:
<% @items.each do |item| %>
<%= render_cell :cart, :item, item %>
<% end %>
If the cell requires more arguments, they can be passed at the end. They will be passed to each cell rendering too:
<%= render_cell_collection :cart, :item, @items, 'hot', 10 %>
is equivalent to:
<% @items.each do |item| %>
<%= render_cell :cart, :item, item, 'hot', 10 %>
<% end %>
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request