Class: Rack::Insight::CachePanel::Stats
- Inherits:
-
Object
- Object
- Rack::Insight::CachePanel::Stats
- Defined in:
- lib/rack/insight/panels/cache_panel/stats.rb
Defined Under Namespace
Classes: Query
Instance Attribute Summary collapse
-
#calls ⇒ Object
readonly
Returns the value of attribute calls.
-
#keys ⇒ Object
readonly
Returns the value of attribute keys.
-
#queries ⇒ Object
readonly
Returns the value of attribute queries.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Instance Method Summary collapse
- #count_queries(method) ⇒ Object
- #deletes ⇒ Object
- #display_time ⇒ Object
- #get_multis ⇒ Object
- #gets ⇒ Object
- #hits ⇒ Object
-
#initialize ⇒ Stats
constructor
A new instance of Stats.
- #misses ⇒ Object
- #queries_to_param ⇒ Object
- #record_call(method, time, hit, key) ⇒ Object
- #sets ⇒ Object
Constructor Details
#initialize ⇒ Stats
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
#calls ⇒ Object (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 |
#keys ⇒ Object (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 |
#queries ⇒ Object (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 |
#time ⇒ Object (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 |
#deletes ⇒ Object
61 62 63 |
# File 'lib/rack/insight/panels/cache_panel/stats.rb', line 61 def deletes count_queries(:delete) end |
#display_time ⇒ Object
49 50 51 |
# File 'lib/rack/insight/panels/cache_panel/stats.rb', line 49 def display_time "%.2fms" % time end |
#get_multis ⇒ Object
65 66 67 |
# File 'lib/rack/insight/panels/cache_panel/stats.rb', line 65 def get_multis count_queries(:get_multi) end |
#gets ⇒ Object
53 54 55 |
# File 'lib/rack/insight/panels/cache_panel/stats.rb', line 53 def gets count_queries(:get) end |
#hits ⇒ Object
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 |
#misses ⇒ Object
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_param ⇒ Object
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 |
#sets ⇒ Object
57 58 59 |
# File 'lib/rack/insight/panels/cache_panel/stats.rb', line 57 def sets count_queries(:set) end |