Class: Rails::Cache::Debugger
- Inherits:
-
Object
- Object
- Rails::Cache::Debugger
show all
- Defined in:
- lib/rails/cache/debugger.rb,
lib/rails/cache/debugger/railtie.rb,
lib/rails/cache/debugger/version.rb,
lib/rails/cache/debugger/subscriber.rb,
lib/rails/cache/debugger/configuration.rb
Defined Under Namespace
Classes: Configuration, Railtie, Subscriber
Constant Summary
collapse
- VERSION =
"0.1.0"
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(cache) ⇒ Debugger
Returns a new instance of Debugger.
26
27
28
|
# File 'lib/rails/cache/debugger.rb', line 26
def initialize(cache)
@cache = cache
end
|
Class Method Details
.configuration ⇒ Object
17
18
19
|
# File 'lib/rails/cache/debugger.rb', line 17
def configuration
@configuration ||= Configuration.new
end
|
21
22
23
|
# File 'lib/rails/cache/debugger.rb', line 21
def configure
yield configuration
end
|
.log(message) ⇒ Object
13
14
15
|
# File 'lib/rails/cache/debugger.rb', line 13
def log(message)
puts message
end
|
Instance Method Details
#delete(key, **options) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/rails/cache/debugger.rb', line 56
def delete(key, **options)
start_time = Time.now
result = @cache.delete(key, **options)
duration = ((Time.now - start_time) * 1000).round(2)
log_cache_event(
event: "cache_delete",
key: key,
duration: duration
)
result
end
|
#exist?(key, **options) ⇒ Boolean
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/rails/cache/debugger.rb', line 68
def exist?(key, **options)
start_time = Time.now
exists = @cache.exist?(key, **options)
duration = ((Time.now - start_time) * 1000).round(2)
log_cache_event(
event: "cache_exist",
key: key,
exists: exists,
duration: duration
)
exists
end
|
#fetch(key, **options) ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/rails/cache/debugger.rb', line 81
def fetch(key, **options)
start_time = Time.now
value = @cache.read(key, **options)
if value.nil?
value = yield
@cache.write(key, value, **options)
duration = ((Time.now - start_time) * 1000).round(2)
log_cache_event(
event: "cache_fetch.miss",
key: key,
value: value,
duration: duration
)
else
duration = ((Time.now - start_time) * 1000).round(2)
log_cache_event(
event: "cache_fetch.hit",
key: key,
value: value,
duration: duration
)
end
value
end
|
#read(key, **options) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/rails/cache/debugger.rb', line 30
def read(key, **options)
start_time = Time.now
value = @cache.read(key, **options)
duration = ((Time.now - start_time) * 1000).round(2)
log_cache_event(
event: value.nil? ? "cache_read.miss" : "cache_read.hit",
key: key,
value: value,
duration: duration
)
value
end
|
#write(key, value, **options) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/rails/cache/debugger.rb', line 43
def write(key, value, **options)
start_time = Time.now
result = @cache.write(key, value, **options)
duration = ((Time.now - start_time) * 1000).round(2)
log_cache_event(
event: "cache_write",
key: key,
value: value,
duration: duration
)
result
end
|