perforated 0.5.0 → 0.6.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/CHANGELOG.md +5 -0
- data/lib/perforated/cache.rb +4 -16
- data/lib/perforated/compatibility/fetch_multi.rb +25 -0
- data/lib/perforated/version.rb +1 -1
- data/lib/perforated.rb +1 -0
- data/spec/perforated/compatibility/fetch_multi_spec.rb +23 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64e25f900f7679d5f4f579b0241ae489e282067f
|
4
|
+
data.tar.gz: 89faaf88ca21ab566ae430bcf191340e979657fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71f125afe780caffb948823f4df8650e03f9909ae20e4fa9bc4d00aae486f9fa2826389150ec75c086091da6adfc084f50f974d9c455f95b333f2c82610424b0
|
7
|
+
data.tar.gz: dcaad74a443699fbaf91c35cee0df77c96b75ffa98c63600f0db07313072e3b181165311d78745a5db681469def7f24a18cbd22fe40b27b1a178f6d3a0971857
|
data/CHANGELOG.md
CHANGED
data/lib/perforated/cache.rb
CHANGED
@@ -9,16 +9,18 @@ module Perforated
|
|
9
9
|
|
10
10
|
def as_json(*)
|
11
11
|
keyed = keyed_enumerable('as-json')
|
12
|
+
keys = keyed.keys.map(&:dup)
|
12
13
|
|
13
|
-
fetch_multi(*
|
14
|
+
Perforated::Compatibility.fetch_multi(*keys) do |key|
|
14
15
|
keyed[key].as_json
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
18
19
|
def to_json(*)
|
19
20
|
keyed = keyed_enumerable('to-json')
|
21
|
+
keys = keyed.keys.map(&:dup)
|
20
22
|
|
21
|
-
json_objects = fetch_multi(*
|
23
|
+
json_objects = Perforated::Compatibility.fetch_multi(*keys) do |key|
|
22
24
|
keyed[key].to_json
|
23
25
|
end
|
24
26
|
|
@@ -27,20 +29,6 @@ module Perforated
|
|
27
29
|
|
28
30
|
private
|
29
31
|
|
30
|
-
# Backward compatible implementation of fetch multi.
|
31
|
-
def fetch_multi(*names)
|
32
|
-
options = {}
|
33
|
-
results = Perforated.cache.read_multi(*names, options)
|
34
|
-
|
35
|
-
names.map do |name|
|
36
|
-
results.fetch(name) do
|
37
|
-
value = yield name
|
38
|
-
Perforated.cache.write(name, value, options)
|
39
|
-
value
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
32
|
def keyed_enumerable(suffix = '')
|
45
33
|
enumerable.inject({}) do |memo, object|
|
46
34
|
memo[key_strategy.expand_cache_key(object, suffix)] = object
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Perforated
|
2
|
+
module Compatibility
|
3
|
+
def self.fetch_multi(*names, &block)
|
4
|
+
if Perforated.cache.respond_to?(:fetch_multi)
|
5
|
+
Perforated.cache.fetch_multi(*names, &block)
|
6
|
+
else
|
7
|
+
custom_fetch_multi(*names, &block)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# Backward compatible implementation of fetch multi.
|
12
|
+
def self.custom_fetch_multi(*names)
|
13
|
+
options = {}
|
14
|
+
results = Perforated.cache.read_multi(*names, options)
|
15
|
+
|
16
|
+
names.map do |name|
|
17
|
+
results.fetch(name) do
|
18
|
+
value = yield name
|
19
|
+
Perforated.cache.write(name, value, options)
|
20
|
+
value
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/perforated/version.rb
CHANGED
data/lib/perforated.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'perforated'
|
2
|
+
|
3
|
+
describe Perforated::Compatibility do
|
4
|
+
after { Perforated.cache = nil }
|
5
|
+
|
6
|
+
describe '.fetch_multi' do
|
7
|
+
it 'uses the fetch_multi method on the configured cache if present' do
|
8
|
+
cache = Perforated.cache = double(:cache, fetch_multi: true)
|
9
|
+
|
10
|
+
Perforated::Compatibility.fetch_multi(:one, :two)
|
11
|
+
|
12
|
+
expect(cache).to have_received(:fetch_multi).with(:one, :two)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'falls back to the custom backfill if the cache does not support it' do
|
16
|
+
cache = Perforated.cache
|
17
|
+
|
18
|
+
Perforated::Compatibility.fetch_multi(:one, :two) do |key|
|
19
|
+
key
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: perforated
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.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: 2013-07-
|
11
|
+
date: 2013-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -83,10 +83,12 @@ files:
|
|
83
83
|
- Rakefile
|
84
84
|
- lib/perforated.rb
|
85
85
|
- lib/perforated/cache.rb
|
86
|
+
- lib/perforated/compatibility/fetch_multi.rb
|
86
87
|
- lib/perforated/strategy/default.rb
|
87
88
|
- lib/perforated/version.rb
|
88
89
|
- perforated.gemspec
|
89
90
|
- spec/perforated/cache_spec.rb
|
91
|
+
- spec/perforated/compatibility/fetch_multi_spec.rb
|
90
92
|
- spec/perforated_spec.rb
|
91
93
|
- spec/spec_helper.rb
|
92
94
|
homepage: https://github.com/sorentwo/perforated
|
@@ -118,5 +120,6 @@ summary: 'The most expensive part of serving a JSON request is converting the se
|
|
118
120
|
this several ways:'
|
119
121
|
test_files:
|
120
122
|
- spec/perforated/cache_spec.rb
|
123
|
+
- spec/perforated/compatibility/fetch_multi_spec.rb
|
121
124
|
- spec/perforated_spec.rb
|
122
125
|
- spec/spec_helper.rb
|