Class: Rack::Insight::CachePanel::Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/insight/panels/cache_panel/stats.rb

Defined Under Namespace

Classes: Query

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStats

Returns a new instance of Stats.



30
31
32
33
34
35
36
# File 'lib/rack/insight/panels/cache_panel/stats.rb', line 30

def initialize
  @queries = []
  @misses =
    @calls = 0
  @time = 0.0
  @keys = []
end

Instance Attribute Details

#callsObject (readonly)

Returns the value of attribute calls.



28
29
30
# File 'lib/rack/insight/panels/cache_panel/stats.rb', line 28

def calls
  @calls
end

#keysObject (readonly)

Returns the value of attribute keys.



28
29
30
# File 'lib/rack/insight/panels/cache_panel/stats.rb', line 28

def keys
  @keys
end

#queriesObject (readonly)

Returns the value of attribute queries.



28
29
30
# File 'lib/rack/insight/panels/cache_panel/stats.rb', line 28

def queries
  @queries
end

#timeObject (readonly)

Returns the value of attribute time.



28
29
30
# File 'lib/rack/insight/panels/cache_panel/stats.rb', line 28

def time
  @time
end

Instance Method Details

#count_queries(method) ⇒ Object



77
78
79
# File 'lib/rack/insight/panels/cache_panel/stats.rb', line 77

def count_queries(method)
  @queries.select { |q| q.method == method }.size
end

#deletesObject



61
62
63
# File 'lib/rack/insight/panels/cache_panel/stats.rb', line 61

def deletes
  count_queries(:delete)
end

#display_timeObject



49
50
51
# File 'lib/rack/insight/panels/cache_panel/stats.rb', line 49

def display_time
  "%.2fms" % time
end

#get_multisObject



65
66
67
# File 'lib/rack/insight/panels/cache_panel/stats.rb', line 65

def get_multis
  count_queries(:get_multi)
end

#getsObject



53
54
55
# File 'lib/rack/insight/panels/cache_panel/stats.rb', line 53

def gets
  count_queries(:get)
end

#hitsObject



69
70
71
# File 'lib/rack/insight/panels/cache_panel/stats.rb', line 69

def hits
  @queries.select { |q| [:get, :get_multi].include?(q.method) && q.hit }.size
end

#missesObject



73
74
75
# File 'lib/rack/insight/panels/cache_panel/stats.rb', line 73

def misses
  @queries.select { |q| [:get, :get_multi].include?(q.method) && !q.hit }.size
end

#queries_to_paramObject



81
82
83
84
85
86
87
# File 'lib/rack/insight/panels/cache_panel/stats.rb', line 81

def queries_to_param
  params = {}
  @queries.each_with_index do |query, index|
    params["keys_#{index}"] = query.keys.first
  end
  params
end

#record_call(method, time, hit, key) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/rack/insight/panels/cache_panel/stats.rb', line 38

def record_call(method, time, hit, key)
  if Array === key
    @queries << Query.new(:get_multi, time, hit, key)
  else
    @queries << Query.new(method.to_sym, time, hit, [key])
  end
  @calls += 1
  @time += time
  @keys += keys
end

#setsObject



57
58
59
# File 'lib/rack/insight/panels/cache_panel/stats.rb', line 57

def sets
  count_queries(:set)
end