Module: Apress::Api::Extensions::Jbuilder::JbuilderTemplate

Defined in:
lib/apress/api/extensions/jbuilder/jbuilder_template.rb

Instance Method Summary collapse

Instance Method Details

#paginating_cache!(collection, key = nil, options = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/apress/api/extensions/jbuilder/jbuilder_template.rb', line 7

def paginating_cache!(collection, key = nil, options = nil)
  if @context.controller.perform_caching
    result = Rails.cache.fetch(_cache_key(key || collection, options), options) do
      {
        headers: _pagination_headers(collection),
        content: _scope { yield self }
      }
    end

    _set_pagination_headers(result[:headers])

    merge! result[:content]
  else
    _set_pagination_headers(_pagination_headers(collection))

    yield
  end
end