Skip to content

Cells rendering for a collection of items, utilizing cache bulk-read.

License

Notifications You must be signed in to change notification settings

GoodLife/cells-collection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Cells rendering for a collection of items, utilizing cache bulk-read.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages