38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/kaminari-cache.rb', line 38
def fetch_page(options = {})
options.reverse_merge!(
:page => 1,
:per => Kaminari.config.max_per_page || Kaminari.config.default_per_page
)
key = cache_key(options)
entries = Rails.cache.fetch(key) do
Rails.logger.info "Cache miss: #{key.to_s}"
scope = self.send(options[:scope]) if options[:scope]
scope = (scope || self).page(options[:page]).per(options[:per])
scope = apply_locale(scope, options[:locale]) if options[:locale]
scope = apply_includes(scope, options[:includes]) if options[:includes]
scope = apply_sort(scope, options[:order]) if options[:order]
Kaminari::PaginatableArray.new(scope.to_a,
:limit => scope.limit_value,
:offset => scope.offset_value,
:total_count => scope.total_count
)
end
end
|