Kaminari Cache

This gem is no longer maintained, and {I wouldn’t even recommend you use it}[https://github.com/jdurand/kaminari-cache/issues/1]!


Kaminari Cache makes caching your Kaminari pagination a breeze

Currently supported:

When using an unsupported cache engine, the entire cache will be flushed when editing a record.

Installation

Add this line to your application's Gemfile:

gem 'kaminari-cache'

Usage

In your controller, simply call Model.fetch_page (instead of Model.page) with an options hash containing :page, :per & :order.

:order can be a Symbol, a Hash or a String depending on your sorting needs.

Example:

In your controller:

@events = Event.fetch_page :page => (params[:page] || 1),
                   :per => 18,
                   :order => {
                     :start => :desc,
                     :updated_at => :desc
                   }
                   # :locale => :fr,
                   # :scope => :latest,
                   # :includes => :occurrences

In your view:

@events.each do |entry|
    # Do your thing
  end

Note that fetch_page returns an array of type Kaminari::PaginatableArray so if you use something like Draper which decorates ActiveRecord collections, you'll need to decorate them manualy and delegate the needed methods:

In an initializer (config/initializers/draper.rb):

Draper::CollectionDecorator.delegate :current_page, :total_pages, :limit_value, :total_count

In your controller:

@events = Draper::CollectionDecorator.new Event.fetch_page(...)

TODO

Contributing to Kaminari Cache

Copyright © 2013-2014 Jim Durand. See LICENSE.txt for further details.