perforated 0.9.1 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -8
- data/lib/perforated/cache.rb +9 -15
- data/lib/perforated/version.rb +1 -1
- data/spec/perforated/cache_spec.rb +4 -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: 907c4447153261709537b4ff03efd368be94f59a
|
4
|
+
data.tar.gz: 2761cf1f6cc3f8938b2eef515972ced97274c968
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98b9a3c654f3908efc2d0e78f3dc1d2f8297cd6554d31ba4d13acfdb903222f8163fecbc534528053fd660edef089dfa8df94dc661df566d6981fdb6086d1e6b
|
7
|
+
data.tar.gz: e03fb7f70a5b36f4e0a4ed36d939b38dda8cbf9bbdb43e88d54f8650f8cf2d5c27793787c48620a7a81fb70990881b956c505a9fabbfa8bd1e119f317b33a183
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,17 @@
|
|
1
|
-
##
|
1
|
+
## v0.10.0 2014-12-10
|
2
|
+
|
3
|
+
* Changed: No longer support batching during serialization. See cb00076 for more
|
4
|
+
details about why it was removed.
|
5
|
+
* Fixed: The result of a yielded block is now used to supply the `cache_key`,
|
6
|
+
which is critical for proper serializer caching.
|
7
|
+
|
8
|
+
## v0.9.1 2014-10-29
|
2
9
|
|
3
10
|
* To preserve the order and limit of ActiveRecord Relations, use of
|
4
11
|
`ActiveRecord::Relation#find_in_batches` has been removed in favor of
|
5
12
|
`Enumerable#each_slice` during batch caching.
|
6
13
|
|
7
|
-
##
|
14
|
+
## v0.9.0 2014-10-09
|
8
15
|
|
9
16
|
* `as_json` and `to_json` now take a block. The block will be applied to each
|
10
17
|
model as it is being cached, allowing for serializers or presenters without
|
@@ -20,33 +27,33 @@
|
|
20
27
|
memory savings (particularly when paired with passing a block through for
|
21
28
|
custom serialization).
|
22
29
|
|
23
|
-
##
|
30
|
+
## v0.8.2 2014-06-27
|
24
31
|
|
25
32
|
* Really force the use of custom `fetch_multi` when using `NullStore`, not just
|
26
33
|
when using `MemoryStore`.
|
27
34
|
|
28
|
-
##
|
35
|
+
## v0.8.1 2014-06-07
|
29
36
|
|
30
37
|
* Force use of custom implementation of `fetch_multi`. This makes using the
|
31
38
|
default ActiveSupport stores (Memory) possible in versions of Rails between
|
32
39
|
4.0 and 4.2.
|
33
40
|
* Use array extract option support in custom fetch.
|
34
41
|
|
35
|
-
##
|
42
|
+
## v0.8.0 2014-06-03
|
36
43
|
|
37
44
|
* Support reconstructing collections of rooted objects and associations.
|
38
45
|
|
39
|
-
##
|
46
|
+
## v0.7.0 2013-07-21
|
40
47
|
|
41
48
|
* Alter the implementation of `fetch_multi` to return a hash rather than an
|
42
49
|
array. This is consistent with the new Dalli implementation, and what should
|
43
50
|
be new the Rails implementation.
|
44
51
|
|
45
|
-
##
|
52
|
+
## v0.6.0 2013-07-13
|
46
53
|
|
47
54
|
* Prevent frozen string errors by duplicating hash keys before fetching.
|
48
55
|
* Use the native cache store's `fetch_multi` implementation if available.
|
49
56
|
|
50
|
-
##
|
57
|
+
## v0.5.0 2013-07-12
|
51
58
|
|
52
59
|
* Initial release!
|
data/lib/perforated/cache.rb
CHANGED
@@ -11,28 +11,18 @@ module Perforated
|
|
11
11
|
@strategy = strategy
|
12
12
|
end
|
13
13
|
|
14
|
-
def to_json(rooted: false,
|
15
|
-
|
16
|
-
|
17
|
-
enumerable.each_slice(batch_size) do |subset|
|
18
|
-
keyed = key_mapped(subset)
|
19
|
-
|
20
|
-
results << fetch_multi(keyed) do |key|
|
21
|
-
if block_given?
|
22
|
-
(yield keyed[key]).to_json
|
23
|
-
else
|
24
|
-
keyed[key].to_json
|
25
|
-
end
|
26
|
-
end.values
|
27
|
-
end
|
14
|
+
def to_json(rooted: false, &block)
|
15
|
+
keyed = key_mapped(enumerable, &block)
|
16
|
+
results = fetch_multi(keyed) { |key| keyed[key].to_json }.values
|
28
17
|
|
29
|
-
|
18
|
+
rebuild(results, rooted)
|
30
19
|
end
|
31
20
|
|
32
21
|
private
|
33
22
|
|
34
23
|
def key_mapped(subset)
|
35
24
|
subset.each_with_object({}) do |object, memo|
|
25
|
+
object = yield(object) if block_given?
|
36
26
|
memo[strategy.expand_cache_key(object)] = object
|
37
27
|
end
|
38
28
|
end
|
@@ -42,5 +32,9 @@ module Perforated
|
|
42
32
|
|
43
33
|
Perforated::Compatibility.fetch_multi(*keys, &block)
|
44
34
|
end
|
35
|
+
|
36
|
+
def rebuild(results, rooted)
|
37
|
+
Perforated::Rebuilder.new(results).rebuild(rooted: rooted)
|
38
|
+
end
|
45
39
|
end
|
46
40
|
end
|
data/lib/perforated/version.rb
CHANGED
@@ -55,6 +55,10 @@ describe Perforated::Cache do
|
|
55
55
|
cache = Perforated::Cache.new([ruby])
|
56
56
|
|
57
57
|
serializer = Struct.new(:lang) do
|
58
|
+
def cache_key
|
59
|
+
lang
|
60
|
+
end
|
61
|
+
|
58
62
|
def to_json
|
59
63
|
{ name: lang.name.upcase }.to_json
|
60
64
|
end
|
@@ -67,7 +71,6 @@ describe Perforated::Cache do
|
|
67
71
|
expect(results).to eq(JSON.dump([{ name: 'RUBY' }]))
|
68
72
|
end
|
69
73
|
|
70
|
-
|
71
74
|
it 'reconstructs rooted objects into a single merged object' do
|
72
75
|
lisps = Family.new('Lisp', ['scheme', 'clojure'])
|
73
76
|
scripts = Family.new('Script', ['perl', 'ruby'])
|
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.10.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: 2014-10
|
11
|
+
date: 2014-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|