readthis 1.5.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/readthis/cache.rb +38 -18
- data/lib/readthis/version.rb +1 -1
- data/spec/readthis/cache_spec.rb +12 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e16646d64b4ceca02395a09548e24ecea98acc2f
|
4
|
+
data.tar.gz: 450ed32fe1925d4bee3f6b1fa43503305c7210ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 456a017c4ceacfb887523a018fff2c2093acff21ddb9fb105e25e408781cb5a8b00b9c455c27f6fec18a8a2c2bc0a2320e8610744471048830dacb273df275c3
|
7
|
+
data.tar.gz: 5061eac72e442c3f235b22719bd3c2bc824b71e4a5add63a6b13cba4ebce8ca8d16ff76593ea9f218e3a231a73ab681dc44fa2dc00eef161d6de4ff97a0943c7
|
data/lib/readthis/cache.rb
CHANGED
@@ -19,21 +19,32 @@ module Readthis
|
|
19
19
|
|
20
20
|
# Creates a new Readthis::Cache object with the given options.
|
21
21
|
#
|
22
|
-
# @option options [Hash]
|
23
|
-
#
|
24
|
-
# @option options [
|
25
|
-
#
|
26
|
-
# @option options [
|
27
|
-
#
|
28
|
-
# @option options [
|
29
|
-
#
|
30
|
-
# @option options [
|
22
|
+
# @option options [Hash] :redis Options that will be passed to the redis
|
23
|
+
# connection
|
24
|
+
# @option options [Boolean] :compress (false) Enable or disable automatic
|
25
|
+
# compression
|
26
|
+
# @option options [Number] :compression_threshold (8k) Minimum string size
|
27
|
+
# for compression
|
28
|
+
# @option options [Number] :expires_in The number of seconds until an entry
|
29
|
+
# expires
|
30
|
+
# @option options [Boolean] :refresh (false) Automatically refresh key
|
31
|
+
# expiration
|
32
|
+
# @option options [Boolean] :retain_nils (false) Whether nil values should
|
33
|
+
# be included in read_multi output
|
34
|
+
# @option options [Module] :marshal (Marshal) Module that responds to
|
35
|
+
# `dump` and `load`
|
36
|
+
# @option options [String] :namespace Prefix used to namespace entries
|
37
|
+
# @option options [Number] :pool_size (5) The number of threads in the pool
|
38
|
+
# @option options [Number] :pool_timeout (5) How long before a thread times
|
39
|
+
# out
|
31
40
|
#
|
32
41
|
# @example Create a new cache instance
|
42
|
+
#
|
33
43
|
# Readthis::Cache.new(namespace: 'cache',
|
34
44
|
# redis: { url: 'redis://localhost:6379/0' })
|
35
45
|
#
|
36
46
|
# @example Create a compressed cache instance
|
47
|
+
#
|
37
48
|
# Readthis::Cache.new(compress: true, compression_threshold: 2048)
|
38
49
|
#
|
39
50
|
def initialize(options = {})
|
@@ -246,19 +257,20 @@ module Readthis
|
|
246
257
|
end
|
247
258
|
end
|
248
259
|
|
249
|
-
#
|
250
|
-
# last argument.
|
260
|
+
# Efficiently read multiple values at once from the cache. Options can be
|
261
|
+
# passed in the last argument.
|
251
262
|
#
|
252
263
|
# @overload read_multi(keys)
|
253
264
|
# Return all values for the given keys.
|
254
265
|
# @param [String] One or more keys to fetch
|
266
|
+
# @param [Hash] options Configuration to override
|
255
267
|
#
|
256
268
|
# @return [Hash] A hash mapping keys to the values found.
|
257
269
|
#
|
258
270
|
# @example
|
259
271
|
#
|
260
|
-
# cache.
|
261
|
-
# cache.read_multi('a', 'b') # => { 'a' => 1, 'b' => nil }
|
272
|
+
# cache.read_multi('a', 'b') # => { 'a' => 1 }
|
273
|
+
# cache.read_multi('a', 'b', retain_nils: true) # => { 'a' => 1, 'b' => nil }
|
262
274
|
#
|
263
275
|
def read_multi(*keys)
|
264
276
|
options = merged_options(extract_options!(keys))
|
@@ -271,7 +283,7 @@ module Readthis
|
|
271
283
|
|
272
284
|
refresh_entity(mapping, store, options)
|
273
285
|
|
274
|
-
keys
|
286
|
+
values_to_hash(keys, values, options)
|
275
287
|
end
|
276
288
|
end
|
277
289
|
|
@@ -318,9 +330,9 @@ module Readthis
|
|
318
330
|
# end
|
319
331
|
#
|
320
332
|
def fetch_multi(*keys)
|
321
|
-
|
322
|
-
|
323
|
-
missing
|
333
|
+
options = extract_options!(keys).merge(retain_nils: true)
|
334
|
+
results = read_multi(*keys, options)
|
335
|
+
missing = {}
|
324
336
|
|
325
337
|
invoke(:fetch_multi, keys) do |_store|
|
326
338
|
results.each do |key, value|
|
@@ -332,7 +344,7 @@ module Readthis
|
|
332
344
|
end
|
333
345
|
end
|
334
346
|
|
335
|
-
write_multi(missing,
|
347
|
+
write_multi(missing, options) if missing.any?
|
336
348
|
|
337
349
|
results
|
338
350
|
end
|
@@ -426,6 +438,14 @@ module Readthis
|
|
426
438
|
@options.merge(options || {})
|
427
439
|
end
|
428
440
|
|
441
|
+
def zipped_results(keys, values, options)
|
442
|
+
zipped = keys.zip(values)
|
443
|
+
|
444
|
+
zipped.select! { |(_, value)| value } unless options[:retain_nils]
|
445
|
+
|
446
|
+
zipped.to_h
|
447
|
+
end
|
448
|
+
|
429
449
|
def pool_options(options)
|
430
450
|
{ size: options.fetch(:pool_size, 5),
|
431
451
|
timeout: options.fetch(:pool_timeout, 5) }
|
data/lib/readthis/version.rb
CHANGED
data/spec/readthis/cache_spec.rb
CHANGED
@@ -210,14 +210,25 @@ RSpec.describe Readthis::Cache do
|
|
210
210
|
cache.write('a', 1)
|
211
211
|
cache.write('b', 2)
|
212
212
|
cache.write('c', '3')
|
213
|
+
cache.write('d', nil)
|
213
214
|
|
214
|
-
expect(cache.read_multi('a', 'b', 'c')).to eq(
|
215
|
+
expect(cache.read_multi('a', 'b', 'c', 'd')).to eq(
|
215
216
|
'a' => 1,
|
216
217
|
'b' => 2,
|
217
218
|
'c' => '3'
|
218
219
|
)
|
219
220
|
end
|
220
221
|
|
222
|
+
it 'can be configured to retain keys with nil values' do
|
223
|
+
cache.write('a', nil)
|
224
|
+
cache.write('b', nil)
|
225
|
+
|
226
|
+
expect(cache.read_multi('a', 'b', retain_nils: true)).to eq(
|
227
|
+
'a' => nil,
|
228
|
+
'b' => nil
|
229
|
+
)
|
230
|
+
end
|
231
|
+
|
221
232
|
it 'respects namespacing' do
|
222
233
|
cache.write('d', 1, namespace: 'cache')
|
223
234
|
cache.write('e', 2, namespace: 'cache')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: readthis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Parker Selbert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|