redis-memo 0.1.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/redis_memo.rb +48 -36
- data/lib/redis_memo/after_commit.rb +2 -2
- data/lib/redis_memo/batch.rb +36 -11
- data/lib/redis_memo/cache.rb +36 -19
- data/lib/redis_memo/connection_pool.rb +4 -3
- data/lib/redis_memo/errors.rb +9 -0
- data/lib/redis_memo/future.rb +22 -13
- data/lib/redis_memo/memoizable.rb +109 -72
- data/lib/redis_memo/memoizable/bump_version.lua +39 -0
- data/lib/redis_memo/memoizable/dependency.rb +10 -11
- data/lib/redis_memo/memoizable/invalidation.rb +68 -66
- data/lib/redis_memo/memoize_method.rb +169 -131
- data/lib/redis_memo/memoize_query.rb +135 -92
- data/lib/redis_memo/memoize_query/cached_select.rb +73 -62
- data/lib/redis_memo/memoize_query/cached_select/bind_params.rb +202 -70
- data/lib/redis_memo/memoize_query/cached_select/connection_adapter.rb +19 -10
- data/lib/redis_memo/memoize_query/invalidation.rb +22 -20
- data/lib/redis_memo/memoize_query/memoize_table_column.rb +1 -0
- data/lib/redis_memo/middleware.rb +3 -1
- data/lib/redis_memo/options.rb +111 -5
- data/lib/redis_memo/railtie.rb +11 -0
- data/lib/redis_memo/redis.rb +15 -5
- data/lib/redis_memo/testing.rb +49 -0
- data/lib/redis_memo/thread_local_var.rb +16 -0
- data/lib/redis_memo/tracer.rb +1 -0
- data/lib/redis_memo/util.rb +25 -0
- metadata +80 -4
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Redis memo can be flaky due to transient network errors (e.g. Redis connection errors), or when
|
4
|
+
# used with async handlers. This class allows users to override the default redis-memo behavior
|
5
|
+
# to be more robust when testing their code that uses redis-memo.
|
6
|
+
module RedisMemo
|
7
|
+
class Testing
|
8
|
+
class << self
|
9
|
+
attr_accessor :__test_mode
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.enable_test_mode(&blk)
|
13
|
+
__set_test_mode(true, &blk)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.disable_test_mode(&blk)
|
17
|
+
__set_test_mode(false, &blk)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.enabled?
|
21
|
+
__test_mode
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.__set_test_mode(mode, &blk)
|
25
|
+
if blk.nil?
|
26
|
+
__test_mode = mode
|
27
|
+
else
|
28
|
+
prev_mode = __test_mode
|
29
|
+
begin
|
30
|
+
__test_mode = mode
|
31
|
+
yield
|
32
|
+
ensure
|
33
|
+
__test_mode = prev_mode
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
module TestOverrides
|
40
|
+
def without_memoization?
|
41
|
+
if RedisMemo::Testing.enabled? && !RedisMemo::Memoizable::Invalidation.class_variable_get(:@@invalidation_queue).empty?
|
42
|
+
return true
|
43
|
+
end
|
44
|
+
|
45
|
+
super
|
46
|
+
end
|
47
|
+
end
|
48
|
+
singleton_class.prepend(TestOverrides)
|
49
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RedisMemo::ThreadLocalVar
|
4
|
+
def self.define(var_name) # :nodoc:
|
5
|
+
thread_key = :"__redis_memo_#{var_name}__"
|
6
|
+
const_set(var_name.to_s.upcase, thread_key)
|
7
|
+
|
8
|
+
define_singleton_method var_name do
|
9
|
+
Thread.current[thread_key]
|
10
|
+
end
|
11
|
+
|
12
|
+
define_singleton_method "#{var_name}=" do |var_val|
|
13
|
+
Thread.current[thread_key] = var_val
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/redis_memo/tracer.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RedisMemo::Util
|
4
|
+
def self.checksum(serialized)
|
5
|
+
Digest::SHA1.base64digest(serialized)
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.deep_sort_hash(orig_hash)
|
9
|
+
{}.tap do |new_hash|
|
10
|
+
orig_hash.sort.each do |k, v|
|
11
|
+
new_hash[k] = v.is_a?(Hash) ? deep_sort_hash(v) : v
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.tagify_parameterized_sql(sql)
|
17
|
+
# replace $1 with ?,
|
18
|
+
# and (?, ?, ? ...) with (?)
|
19
|
+
sql.gsub(/(\$\d+)/, '?').gsub(/((, *)*\?)+/, '?')
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.uuid
|
23
|
+
SecureRandom.uuid
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-memo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chan Zuckerberg Initiative
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '5.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: connection_pool
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.2.3
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.2.3
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: redis
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,19 +53,19 @@ dependencies:
|
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: 4.0.1
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
56
|
+
name: ruby2_keywords
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - ">="
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
61
|
+
version: '0'
|
48
62
|
type: :runtime
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: activerecord
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,6 +136,20 @@ dependencies:
|
|
122
136
|
- - ">="
|
123
137
|
- !ruby/object:Gem::Version
|
124
138
|
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: railties
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '5.2'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '5.2'
|
125
153
|
- !ruby/object:Gem::Dependency
|
126
154
|
name: rake
|
127
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,6 +178,48 @@ dependencies:
|
|
150
178
|
- - "~>"
|
151
179
|
- !ruby/object:Gem::Version
|
152
180
|
version: '3.2'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: rubocop
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: rubocop-performance
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
209
|
+
- !ruby/object:Gem::Dependency
|
210
|
+
name: rubocop-rspec
|
211
|
+
requirement: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - ">="
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: '0'
|
216
|
+
type: :development
|
217
|
+
prerelease: false
|
218
|
+
version_requirements: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - ">="
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: '0'
|
153
223
|
- !ruby/object:Gem::Dependency
|
154
224
|
name: simplecov
|
155
225
|
requirement: !ruby/object:Gem::Requirement
|
@@ -176,8 +246,10 @@ files:
|
|
176
246
|
- lib/redis_memo/batch.rb
|
177
247
|
- lib/redis_memo/cache.rb
|
178
248
|
- lib/redis_memo/connection_pool.rb
|
249
|
+
- lib/redis_memo/errors.rb
|
179
250
|
- lib/redis_memo/future.rb
|
180
251
|
- lib/redis_memo/memoizable.rb
|
252
|
+
- lib/redis_memo/memoizable/bump_version.lua
|
181
253
|
- lib/redis_memo/memoizable/dependency.rb
|
182
254
|
- lib/redis_memo/memoizable/invalidation.rb
|
183
255
|
- lib/redis_memo/memoize_method.rb
|
@@ -191,8 +263,12 @@ files:
|
|
191
263
|
- lib/redis_memo/memoize_query/model_callback.rb
|
192
264
|
- lib/redis_memo/middleware.rb
|
193
265
|
- lib/redis_memo/options.rb
|
266
|
+
- lib/redis_memo/railtie.rb
|
194
267
|
- lib/redis_memo/redis.rb
|
268
|
+
- lib/redis_memo/testing.rb
|
269
|
+
- lib/redis_memo/thread_local_var.rb
|
195
270
|
- lib/redis_memo/tracer.rb
|
271
|
+
- lib/redis_memo/util.rb
|
196
272
|
homepage: https://github.com/chanzuckerberg/redis-memo
|
197
273
|
licenses:
|
198
274
|
- MIT
|