Module: PhusionPassenger::ClassicRailsExtensions::AnalyticsLogging::CacheStoreExtension

Defined in:
lib/phusion_passenger/classic_rails_extensions/analytics_logging/as_cache_extension.rb

Instance Method Summary collapse

Instance Method Details

#fetch_2_1(key, options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/phusion_passenger/classic_rails_extensions/analytics_logging/as_cache_extension.rb', line 29

def fetch_2_1(key, options = {})
	@logger_off = true
	if !options[:force] && value = read(key, options)
		@logger_off = false
		log("hit", key, options)
		PhusionPassenger.log_cache_hit(nil, key)
		value
	elsif block_given?
		@logger_off = false
		log("miss", key, options)

		value = nil
		seconds = Benchmark.realtime { value = yield }

		@logger_off = true
		write(key, value, options)
		@logger_off = false

		log("write (will save #{'%.5f' % seconds})", key, nil)
		PhusionPassenger.log_cache_miss(nil, key, seconds * 1_000_000)

		value
	else
		PhusionPassenger.log_cache_miss(nil, key)
		value
	end
end

#fetch_2_2(key, options = {}) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/phusion_passenger/classic_rails_extensions/analytics_logging/as_cache_extension.rb', line 57

def fetch_2_2(key, options = {})
	@logger_off = true
	if !options[:force] && value = read(key, options)
		@logger_off = false
		log("hit", key, options)
		PhusionPassenger.log_cache_hit(nil, key)
		value
	elsif block_given?
		@logger_off = false
		log("miss", key, options)

		value = nil
		seconds = Benchmark.realtime { value = yield }

		@logger_off = true
		write(key, value, options)
		@logger_off = false

		log("write (will save #{'%.2f' % (seconds * 1000)}ms)", key, nil)
		PhusionPassenger.log_cache_miss(nil, key, seconds * 1_000_000)

		value
	else
		PhusionPassenger.log_cache_miss(nil, key)
		value
	end
end

#fetch_2_3(key, options = {}) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/phusion_passenger/classic_rails_extensions/analytics_logging/as_cache_extension.rb', line 85

def fetch_2_3(key, options = {})
	@logger_off = true
	if !options[:force] && value = read(key, options)
		@logger_off = false
		log("hit", key, options)
		PhusionPassenger.log_cache_hit(nil, key)
		value
	elsif block_given?
		@logger_off = false
		log("miss", key, options)

		value = nil
		ms = Benchmark.ms { value = yield }

		@logger_off = true
		write(key, value, options)
		@logger_off = false

		log('write (will save %.2fms)' % ms, key, nil)
		PhusionPassenger.log_cache_miss(nil, key, ms * 1_000)

		value
	else
		PhusionPassenger.log_cache_miss(nil, key)
		value
	end
end