Class: Rack::Bug::CachePanel

Inherits:
Panel
  • Object
show all
Defined in:
lib/rack/bug/panels/cache_panel.rb,
lib/rack/bug/panels/cache_panel/stats.rb,
lib/rack/bug/panels/cache_panel/panel_app.rb

Defined Under Namespace

Classes: PanelApp, Stats

Instance Attribute Summary

Attributes inherited from Panel

#request

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Panel

#after, #before, #call, #has_content?, #initialize, #render

Methods included from Render

#compile, #compile!, #compiled_source, #method_name, #method_name_without_locals, #render_template, #signed_params

Constructor Details

This class inherits a constructor from Rack::Bug::Panel

Class Method Details

.record(method, *keys, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/rack/bug/panels/cache_panel.rb', line 11

def self.record(method, *keys, &block)
  return block.call unless Rack::Bug.enabled?

  start_time = Time.now
  result = block.call
  total_time = Time.now - start_time
  hit = result.nil? ? false : true
  stats.record_call(method, total_time * 1_000, hit, *keys)
  return result
end

.resetObject



22
23
24
# File 'lib/rack/bug/panels/cache_panel.rb', line 22

def self.reset
  Thread.current["rack.bug.cache"] = Stats.new
end

.statsObject



26
27
28
# File 'lib/rack/bug/panels/cache_panel.rb', line 26

def self.stats
  Thread.current["rack.bug.cache"] ||= Stats.new
end

Instance Method Details

#contentObject



42
43
44
45
46
# File 'lib/rack/bug/panels/cache_panel.rb', line 42

def content
  result = render_template "panels/cache", :stats => self.class.stats
  self.class.reset
  return result
end

#headingObject



38
39
40
# File 'lib/rack/bug/panels/cache_panel.rb', line 38

def heading
  "Cache: %.2fms (#{self.class.stats.queries.size} calls)" % self.class.stats.time
end

#nameObject



34
35
36
# File 'lib/rack/bug/panels/cache_panel.rb', line 34

def name
  "cache"
end

#panel_appObject



30
31
32
# File 'lib/rack/bug/panels/cache_panel.rb', line 30

def panel_app
  PanelApp.new
end