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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 683803eb90edeac727bca419d2f5ab5e4f4db280
4
- data.tar.gz: 2d465ab7a114dd20db77d731003fba5933fb5428
3
+ metadata.gz: 64e25f900f7679d5f4f579b0241ae489e282067f
4
+ data.tar.gz: 89faaf88ca21ab566ae430bcf191340e979657fd
5
5
  SHA512:
6
- metadata.gz: d3df769d45345f7d02d3653703c8da995954ea6686b51a7bc055b085861a554ab5a512d3cead7be248754c7b98f8403c8cb2da96ca654d934da93c6021a3182f
7
- data.tar.gz: d5266599fb68f53c1d95e38f06cf7b4b000d3e98990c59de7326fca99a024a636d993246d0339f9febc224d2f46155d506776dbc1abc15face89652a53a3ab6b
6
+ metadata.gz: 71f125afe780caffb948823f4df8650e03f9909ae20e4fa9bc4d00aae486f9fa2826389150ec75c086091da6adfc084f50f974d9c455f95b333f2c82610424b0
7
+ data.tar.gz: dcaad74a443699fbaf91c35cee0df77c96b75ffa98c63600f0db07313072e3b181165311d78745a5db681469def7f24a18cbd22fe40b27b1a178f6d3a0971857
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## Version 0.6.0
2
+
3
+ * Prevent frozen string errors by duplicating hash keys before fetching.
4
+ * Use the native cache store's `fetch_multi` implementation if available.
5
+
1
6
  ## Version 0.5.0
2
7
 
3
8
  * Initial release!
@@ -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(*keyed.keys) do |key|
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(*keyed.keys) do |key|
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
@@ -1,3 +1,3 @@
1
1
  module Perforated
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  end
data/lib/perforated.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'active_support/cache'
2
2
  require 'json'
3
3
  require 'perforated/cache'
4
+ require 'perforated/compatibility/fetch_multi'
4
5
  require 'perforated/strategy/default'
5
6
  require 'perforated/version'
6
7
 
@@ -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.5.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-12 00:00:00.000000000 Z
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