No commit activity in last 3 years
No release in over 3 years
Cells rendering for a collection of items, utilizing cache bulk-read.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
~> 2.14

Runtime

~> 3.9
 Project Readme

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

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request