moneta 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +26 -8
- data/CHANGES +6 -0
- data/CONTRIBUTORS +2 -1
- data/Gemfile +7 -5
- data/README.md +2 -6
- data/feature_matrix.yaml +0 -10
- data/lib/moneta.rb +9 -9
- data/lib/moneta/adapters/mongo.rb +256 -7
- data/lib/moneta/adapters/redis.rb +5 -1
- data/lib/moneta/adapters/sequel.rb +45 -464
- data/lib/moneta/adapters/sequel/mysql.rb +66 -0
- data/lib/moneta/adapters/sequel/postgres.rb +80 -0
- data/lib/moneta/adapters/sequel/postgres_hstore.rb +240 -0
- data/lib/moneta/adapters/sequel/sqlite.rb +57 -0
- data/lib/moneta/adapters/sqlite.rb +7 -7
- data/lib/moneta/create_support.rb +21 -0
- data/lib/moneta/dbm_adapter.rb +31 -0
- data/lib/moneta/{mixins.rb → defaults.rb} +1 -302
- data/lib/moneta/each_key_support.rb +27 -0
- data/lib/moneta/expires_support.rb +60 -0
- data/lib/moneta/hash_adapter.rb +68 -0
- data/lib/moneta/increment_support.rb +16 -0
- data/lib/moneta/nil_values.rb +35 -0
- data/lib/moneta/option_support.rb +51 -0
- data/lib/moneta/transformer/helper/bson.rb +5 -15
- data/lib/moneta/version.rb +1 -1
- data/lib/rack/cache/moneta.rb +14 -15
- data/moneta.gemspec +7 -9
- data/script/benchmarks +1 -2
- data/script/contributors +11 -6
- data/spec/active_support/cache_moneta_store_spec.rb +27 -29
- data/spec/features/concurrent_increment.rb +2 -3
- data/spec/features/create_expires.rb +15 -15
- data/spec/features/default_expires.rb +11 -12
- data/spec/features/expires.rb +215 -210
- data/spec/helper.rb +16 -33
- data/spec/moneta/adapters/mongo/adapter_mongo_spec.rb +16 -1
- data/spec/moneta/adapters/mongo/adapter_mongo_with_default_expires_spec.rb +1 -1
- data/spec/moneta/adapters/mongo/standard_mongo_spec.rb +1 -1
- data/spec/moneta/adapters/sequel/adapter_sequel_spec.rb +7 -34
- data/spec/moneta/adapters/sequel/helper.rb +37 -0
- data/spec/moneta/adapters/sequel/standard_sequel_spec.rb +4 -10
- data/spec/moneta/adapters/sequel/standard_sequel_with_expires_spec.rb +7 -8
- data/spec/moneta/proxies/shared/shared_unix_spec.rb +10 -0
- data/spec/restserver.rb +15 -0
- metadata +39 -58
- data/lib/moneta/adapters/mongo/base.rb +0 -103
- data/lib/moneta/adapters/mongo/moped.rb +0 -166
- data/lib/moneta/adapters/mongo/official.rb +0 -156
- data/spec/moneta/adapters/mongo/adapter_mongo_moped_spec.rb +0 -26
- data/spec/moneta/adapters/mongo/adapter_mongo_moped_with_default_expires_spec.rb +0 -14
- data/spec/moneta/adapters/mongo/adapter_mongo_official_spec.rb +0 -27
- data/spec/moneta/adapters/mongo/adapter_mongo_official_with_default_expires_spec.rb +0 -14
- data/spec/moneta/adapters/mongo/standard_mongo_moped_spec.rb +0 -7
- data/spec/moneta/adapters/mongo/standard_mongo_official_spec.rb +0 -7
- data/spec/quality_spec.rb +0 -51
data/spec/features/expires.rb
CHANGED
@@ -3,289 +3,294 @@ shared_examples :expires do
|
|
3
3
|
raise "t_res must be <= min_ttl" unless t_res <= min_ttl
|
4
4
|
end
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
6
|
+
# All methods that are used for updating that include an :expires parameter
|
7
|
+
shared_examples :updater_expiry do
|
8
|
+
context "with a positive numeric :expires parameter" do
|
9
|
+
before do
|
10
|
+
updater.call(expires: min_ttl)
|
11
|
+
end
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
13
|
+
it 'causes the value to expire after the given number of seconds' do
|
14
|
+
keys.zip(values).each do |key, value|
|
15
|
+
expect(store.load(key)).to eq value
|
16
|
+
expect(store[key]).to eq value
|
17
|
+
end
|
18
|
+
advance min_ttl
|
19
|
+
2.times { advance_next_tick }
|
20
|
+
keys.each do |key, value|
|
21
|
+
expect(store.load(key)).to be_nil
|
22
|
+
expect(store[key]).to be_nil
|
24
23
|
end
|
25
24
|
end
|
25
|
+
end
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
27
|
+
shared_examples :updater_no_expires do
|
28
|
+
it 'causes the value not to expire after the given number of seconds' do
|
29
|
+
updater.call(expires: expires)
|
30
|
+
keys.zip(values).each do |key, value|
|
31
|
+
expect(store.load(key)).to eq value
|
32
|
+
expect(store[key]).to eq value
|
33
|
+
end
|
34
|
+
advance min_ttl
|
35
|
+
2.times { advance_next_tick }
|
36
|
+
keys.zip(values).each do |key, value|
|
37
|
+
expect(store.load(key)).to eq value
|
38
|
+
expect(store[key]).to eq value
|
39
39
|
end
|
40
40
|
end
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
context "with a zero :expires parameter" do
|
44
|
+
let(:expires) { 0 }
|
45
|
+
include_examples :updater_no_expires
|
46
|
+
end
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
48
|
+
context "with a false :expires parameter" do
|
49
|
+
let(:expires) { false }
|
50
|
+
include_examples :updater_no_expires
|
51
51
|
end
|
52
|
+
end
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
54
|
+
# All methods that are used to for loading, and that include an expire parameter
|
55
|
+
shared_examples :loader_expiry do
|
56
|
+
it "does not affect expiry if the value is not present" do
|
57
|
+
expect(loader.call(expires: min_ttl)).to be_absent
|
58
|
+
expect(loader.call).to be_absent
|
59
|
+
end
|
59
60
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
61
|
+
shared_examples :loader_expires do
|
62
|
+
context 'when passed a positive numeric :expires parameter' do
|
63
|
+
it 'changes the expiry of the value(s) to the given number of seconds' do
|
64
|
+
expect(loader.call).to be_present
|
65
|
+
expect(loader.call(expires: min_ttl + 2 * t_res)).to be_present
|
66
|
+
advance min_ttl
|
67
|
+
advance_next_tick
|
68
|
+
expect(loader.call).to be_present
|
69
|
+
2.times { advance_next_tick }
|
70
|
+
expect(loader.call).to be_absent
|
70
71
|
end
|
71
72
|
end
|
73
|
+
end
|
72
74
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
end
|
75
|
+
context 'with previously stored expiring value(s)' do
|
76
|
+
before do
|
77
|
+
keys.zip(values).each do |key, value|
|
78
|
+
store.store(key, value, expires: min_ttl)
|
78
79
|
end
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
80
|
+
end
|
81
|
+
include_examples :loader_expires
|
82
|
+
|
83
|
+
shared_examples :loader_no_expires do
|
84
|
+
it "changes the expiry of the value(s) so that they don't expire" do
|
85
|
+
expect(loader.call(expires: expires)).to be_present
|
86
|
+
advance min_ttl
|
87
|
+
advance_next_tick
|
88
|
+
expect(loader.call).to be_present
|
87
89
|
end
|
90
|
+
end
|
88
91
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
92
|
+
context "when passed a zero :expires parameter" do
|
93
|
+
let(:expires) { 0 }
|
94
|
+
include_examples :loader_no_expires
|
95
|
+
end
|
93
96
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
97
|
+
context "when passed false :expires parameter" do
|
98
|
+
let(:expires) { false }
|
99
|
+
include_examples :loader_no_expires
|
100
|
+
end
|
98
101
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
102
|
+
shared_examples :loader_no_effect do
|
103
|
+
it 'does not affect the expiry time' do
|
104
|
+
expect(loader_no_effect.call).to be_present
|
105
|
+
advance min_ttl
|
106
|
+
advance_next_tick
|
107
|
+
expect(loader.call).to be_absent
|
105
108
|
end
|
109
|
+
end
|
106
110
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
+
context 'when passed a nil :expires parameter' do
|
112
|
+
let(:loader_no_effect) { lambda { loader.call(expires: nil) } }
|
113
|
+
include_examples :loader_no_effect
|
114
|
+
end
|
111
115
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
end
|
116
|
+
context 'when not passed an :expires parameter' do
|
117
|
+
let(:loader_no_effect) { loader }
|
118
|
+
include_examples :loader_no_effect
|
116
119
|
end
|
120
|
+
end
|
117
121
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
end
|
122
|
+
context "with previously stored not expiring value(s)" do
|
123
|
+
before do
|
124
|
+
keys.zip(values).each do |key, value|
|
125
|
+
store.store(key, value, expires: false)
|
123
126
|
end
|
124
|
-
include_examples :loader_expires
|
125
127
|
end
|
128
|
+
include_examples :loader_expires
|
126
129
|
end
|
130
|
+
end
|
127
131
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
end
|
132
|
+
describe '#store' do
|
133
|
+
let(:keys) { ['key1'] }
|
134
|
+
let(:values) { ['value1'] }
|
135
|
+
let(:updater) do
|
136
|
+
lambda do |**options|
|
137
|
+
expect(store.store(keys[0], values[0], options)).to eq values[0]
|
135
138
|
end
|
139
|
+
end
|
136
140
|
|
137
|
-
|
141
|
+
include_examples :updater_expiry
|
142
|
+
end
|
143
|
+
|
144
|
+
describe '#load' do
|
145
|
+
let(:keys) { ['key1'] }
|
146
|
+
let(:values) { ['value1'] }
|
147
|
+
let(:loader) do
|
148
|
+
lambda { |**options| store.load('key1', options) }
|
149
|
+
end
|
150
|
+
let(:be_present) { eq 'value1' }
|
151
|
+
let(:be_absent) { be_nil }
|
152
|
+
|
153
|
+
include_examples :loader_expiry
|
154
|
+
end
|
155
|
+
|
156
|
+
describe '#key?' do
|
157
|
+
let(:keys) { ['key1'] }
|
158
|
+
let(:values) { ['value1'] }
|
159
|
+
let(:loader) do
|
160
|
+
lambda { |**options| store.key?('key1', options) }
|
138
161
|
end
|
162
|
+
let(:be_present) { be true }
|
163
|
+
let(:be_absent) { be false }
|
164
|
+
|
165
|
+
include_examples :loader_expiry
|
166
|
+
end
|
139
167
|
|
140
|
-
|
141
|
-
|
142
|
-
|
168
|
+
describe '#fetch' do
|
169
|
+
let(:keys) { ['key1'] }
|
170
|
+
let(:values) { ['value1'] }
|
171
|
+
let(:be_present) { eq 'value1' }
|
172
|
+
|
173
|
+
context "with default given as second parameter" do
|
143
174
|
let(:loader) do
|
144
|
-
lambda { |**options| store.
|
175
|
+
lambda { |**options| store.fetch('key1', 'missing', options) }
|
145
176
|
end
|
146
|
-
let(:
|
147
|
-
let(:be_absent) { be_nil }
|
177
|
+
let(:be_absent) { eq 'missing' }
|
148
178
|
|
149
179
|
include_examples :loader_expiry
|
150
180
|
end
|
151
181
|
|
152
|
-
|
153
|
-
let(:keys) { ['key1'] }
|
154
|
-
let(:values) { ['value1'] }
|
182
|
+
context "with default given as a block" do
|
155
183
|
let(:loader) do
|
156
|
-
lambda { |**options| store.
|
184
|
+
lambda { |**options| store.fetch('key1', options) { 'missing' } }
|
157
185
|
end
|
158
|
-
let(:
|
159
|
-
let(:be_absent) { be false }
|
186
|
+
let(:be_absent) { eq 'missing' }
|
160
187
|
|
161
188
|
include_examples :loader_expiry
|
162
189
|
end
|
163
190
|
|
164
|
-
|
165
|
-
let(:
|
166
|
-
|
167
|
-
let(:be_present) { eq 'value1' }
|
168
|
-
|
169
|
-
context "with default given as second parameter" do
|
170
|
-
let(:loader) do
|
171
|
-
lambda { |**options| store.fetch('key1', 'missing', options) }
|
172
|
-
end
|
173
|
-
let(:be_absent) { eq 'missing' }
|
174
|
-
|
175
|
-
include_examples :loader_expiry
|
191
|
+
context "with nil default given" do
|
192
|
+
let(:loader) do
|
193
|
+
lambda { |**options| store.fetch('key1', nil, options) }
|
176
194
|
end
|
195
|
+
let(:be_absent) { be_nil }
|
177
196
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
end
|
182
|
-
let(:be_absent) { eq 'missing' }
|
197
|
+
include_examples :loader_expiry
|
198
|
+
end
|
199
|
+
end
|
183
200
|
|
184
|
-
|
201
|
+
describe '#delete' do
|
202
|
+
context 'with an already expired value' do
|
203
|
+
before do
|
204
|
+
store.store('key2', 'val2', expires: min_ttl)
|
205
|
+
expect(store['key2']).to eq 'val2'
|
206
|
+
advance min_ttl
|
207
|
+
advance_next_tick
|
185
208
|
end
|
186
209
|
|
187
|
-
|
188
|
-
|
189
|
-
lambda { |**options| store.fetch('key1', nil, options) }
|
190
|
-
end
|
191
|
-
let(:be_absent) { be_nil }
|
192
|
-
|
193
|
-
include_examples :loader_expiry
|
210
|
+
it 'does not return the expired value' do
|
211
|
+
expect(store.delete('key2')).to be_nil
|
194
212
|
end
|
195
213
|
end
|
214
|
+
end
|
196
215
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
end
|
216
|
+
describe '#expires' do
|
217
|
+
it "returns a store with access to the same items" do
|
218
|
+
store.store('persistent_key', 'persistent_value', expires: false)
|
219
|
+
store_expires = store.expires(min_ttl)
|
220
|
+
expect(store_expires['persistent_key']).to eq 'persistent_value'
|
221
|
+
end
|
204
222
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
223
|
+
it "returns a store with default expiry set" do
|
224
|
+
store_expires = store.expires(min_ttl)
|
225
|
+
expect(store_expires.store('key1', 'val1')).to eq 'val1'
|
226
|
+
expect(store_expires['key1']).to eq 'val1'
|
227
|
+
advance min_ttl
|
228
|
+
advance_next_tick
|
229
|
+
expect(store['key1']).to be_nil
|
209
230
|
end
|
231
|
+
end
|
210
232
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
233
|
+
describe '#merge!' do
|
234
|
+
let(:keys) { ['key1', 'key2'] }
|
235
|
+
let(:values) { ['value1', 'value2'] }
|
236
|
+
let(:updater) do
|
237
|
+
lambda do |**options|
|
238
|
+
expect(store.merge!(keys.zip(values), options)).to eq store
|
216
239
|
end
|
240
|
+
end
|
217
241
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
242
|
+
include_examples :updater_expiry
|
243
|
+
end
|
244
|
+
|
245
|
+
describe '#values_at' do
|
246
|
+
let(:keys) { ['key1', 'key2'] }
|
247
|
+
let(:values) { ['value1', 'value2'] }
|
248
|
+
let(:loader) do
|
249
|
+
lambda { |**options| store.values_at('key1', 'key2', **options) }
|
225
250
|
end
|
251
|
+
let(:be_present) { eq ['value1', 'value2'] }
|
252
|
+
let(:be_absent) { eq [nil, nil] }
|
226
253
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
254
|
+
include_examples :loader_expiry
|
255
|
+
end
|
256
|
+
|
257
|
+
describe '#fetch_values' do
|
258
|
+
let(:keys) { ['key1', 'key2'] }
|
259
|
+
let(:values) { ['value1', 'value2'] }
|
260
|
+
let(:be_present) { eq ['value1', 'value2'] }
|
261
|
+
|
262
|
+
context 'with default values given via a block' do
|
263
|
+
let(:loader) do
|
231
264
|
lambda do |**options|
|
232
|
-
|
265
|
+
store.fetch_values('key1', 'key2', **options) { |k| "#{k} missing" }
|
233
266
|
end
|
234
267
|
end
|
268
|
+
let(:be_absent) { eq ['key1 missing', 'key2 missing'] }
|
235
269
|
|
236
|
-
include_examples :
|
270
|
+
include_examples :loader_expiry
|
237
271
|
end
|
238
272
|
|
239
|
-
|
240
|
-
let(:keys) { ['key1', 'key2'] }
|
241
|
-
let(:values) { ['value1', 'value2'] }
|
273
|
+
context 'without default values given' do
|
242
274
|
let(:loader) do
|
243
|
-
lambda
|
275
|
+
lambda do |**options|
|
276
|
+
store.fetch_values('key1', 'key2', **options)
|
277
|
+
end
|
244
278
|
end
|
245
|
-
let(:be_present) { eq ['value1', 'value2'] }
|
246
279
|
let(:be_absent) { eq [nil, nil] }
|
247
280
|
|
248
281
|
include_examples :loader_expiry
|
249
282
|
end
|
283
|
+
end
|
250
284
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
context 'with default values given via a block' do
|
257
|
-
let(:loader) do
|
258
|
-
lambda do |**options|
|
259
|
-
store.fetch_values('key1', 'key2', **options) { |k| "#{k} missing" }
|
260
|
-
end
|
261
|
-
end
|
262
|
-
let(:be_absent) { eq ['key1 missing', 'key2 missing'] }
|
263
|
-
|
264
|
-
include_examples :loader_expiry
|
265
|
-
end
|
266
|
-
|
267
|
-
context 'without default values given' do
|
268
|
-
let(:loader) do
|
269
|
-
lambda do |**options|
|
270
|
-
store.fetch_values('key1', 'key2', **options)
|
271
|
-
end
|
272
|
-
end
|
273
|
-
let(:be_absent) { eq [nil, nil] }
|
274
|
-
|
275
|
-
include_examples :loader_expiry
|
276
|
-
end
|
285
|
+
describe '#slice' do
|
286
|
+
let(:keys) { ['key1', 'key2'] }
|
287
|
+
let(:values) { ['value1', 'value2'] }
|
288
|
+
let(:loader) do
|
289
|
+
lambda { |**options| store.slice('key1', 'key2', **options) }
|
277
290
|
end
|
291
|
+
let(:be_present) { contain_exactly(['key1', 'value1'], ['key2', 'value2']) }
|
292
|
+
let(:be_absent) { be_empty }
|
278
293
|
|
279
|
-
|
280
|
-
let(:keys) { ['key1', 'key2'] }
|
281
|
-
let(:values) { ['value1', 'value2'] }
|
282
|
-
let(:loader) do
|
283
|
-
lambda { |**options| store.slice('key1', 'key2', **options) }
|
284
|
-
end
|
285
|
-
let(:be_present) { contain_exactly(['key1', 'value1'], ['key2', 'value2']) }
|
286
|
-
let(:be_absent) { be_empty }
|
287
|
-
|
288
|
-
include_examples :loader_expiry
|
289
|
-
end
|
294
|
+
include_examples :loader_expiry
|
290
295
|
end
|
291
296
|
end
|