Class: OkComputer::CacheCheckSolidCache

Inherits:
Check
  • Object
show all
Defined in:
lib/ok_computer/built_in_checks/cache_check_solid_cache.rb

Overview

Verifies that Rails cache is set up and can speak with SolidCache

Constant Summary

Constants inherited from Check

OkComputer::Check::CheckNotDefined

Instance Attribute Summary

Attributes inherited from Check

#failure_occurred, #message, #registrant_name, #time

Instance Method Summary collapse

Methods inherited from Check

#<=>, #clear, #mark_failure, #mark_message, #run, #success?, #to_json, #to_text, #with_benchmarking

Instance Method Details

#checkObject

Public: Check whether the cache is active



5
6
7
8
9
10
# File 'lib/ok_computer/built_in_checks/cache_check_solid_cache.rb', line 5

def check
  mark_message "Cache is available (#{stats})"
rescue ConnectionFailed => e
  mark_failure
  mark_message "Error: '#{e}'"
end

#statsObject

Public: Outputs stats string for cache



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ok_computer/built_in_checks/cache_check_solid_cache.rb', line 13

def stats
  return "" unless Rails.cache.respond_to? :stats

  stats = Rails.cache.stats
  connection_stats = stats[:connection_stats][SolidCache::Entry.current_shard]

  max_entries = connection_stats[:max_entries]
  current_entries = connection_stats[:entries]
  max_age = connection_stats[:max_age]
  oldest_age = connection_stats[:oldest_age]

  age_text = if oldest_age
    "oldest: #{format_duration(oldest_age)}, max: #{format_duration(max_age)}"
  else
    "no entries"
  end

  "entries: #{current_entries}/#{max_entries}, #{age_text}, #{stats[:connections]} connections"
rescue => e
  raise ConnectionFailed, e
end