Class: Rack::Bug::CachePanel
- Inherits:
-
Panel
- Object
- Panel
- Rack::Bug::CachePanel
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
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
|
.reset ⇒ Object
21
22
23
|
# File 'lib/rack/bug/panels/cache_panel.rb', line 21
def self.reset
Thread.current["rack.bug.cache"] = Stats.new
end
|
.stats ⇒ Object
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
#content ⇒ Object
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
|
#heading ⇒ Object
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
|
#name ⇒ Object
33
34
35
|
# File 'lib/rack/bug/panels/cache_panel.rb', line 33
def name
"cache"
end
|
#panel_app ⇒ Object
29
30
31
|
# File 'lib/rack/bug/panels/cache_panel.rb', line 29
def panel_app
PanelApp.new
end
|