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
28
29
30
31
32
33
34
35
36
# File 'app/controllers/fastentry/dashboard_controller.rb', line 5

def index
  @keys = Rails.cache.instance_variable_get(:@data).keys

  if params[:query].present?
    @keys = @keys.select { |key| key.downcase.include?(params[:query].downcase) }
  end

  @number_of_pages = (@keys.count / @per_page.to_f).ceil

  @keys = @keys[@offset, @per_page] || []

  @cached = []
  @keys.each do |key|
    # Prevent from crashing if expiration can't be read (temporary fix)
    begin
      expiration_date = Rails.cache.send(:read_entry, key, {}).expires_at
    rescue
      expiration_date = nil
    end

    # Only include keys that rails can read
    begin
      value = Rails.cache.read(key)

      @cached << {
        cache_key: key,
        cache_value: value,
        expiration: (Time.at(expiration_date) if expiration_date.present?)
      }
    end
  end
end