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



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

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



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

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

.statsObject



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

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

Instance Method Details

#contentObject



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

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

#headingObject



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

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

#nameObject



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

def name
  "cache"
end

#panel_appObject



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

def panel_app
  PanelApp.new
end