Class: Fastentry::DashboardController

Inherits:
ApplicationController show all
Defined in:
app/controllers/fastentry/dashboard_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/fastentry/dashboard_controller.rb', line 5

def index
  total_keys = 0

  if params[:query].present?
    @keys = Fastentry.cache.search(query: params[:query])
    total_keys = @keys.count
    @keys = @keys.try(:[], @page * @per_page, @per_page) || []
  else
    @keys = Fastentry.cache.select(from: @page * @per_page, amount: @per_page)
    total_keys = Fastentry.cache.number_of_keys
  end

  @number_of_pages = (total_keys / @per_page.to_f).ceil

  @cached =
    @keys.map do |key|
      {
        cache_key: key,
        cache_value: Fastentry.cache.read(key),
        expiration: Fastentry.cache.expiration_for(key)
      }
    end
end