identity_cache 0.3.2 → 0.4.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 +4 -0
- data/dev.yml +3 -0
- data/lib/identity_cache.rb +2 -15
- data/lib/identity_cache/configuration_dsl.rb +1 -5
- data/lib/identity_cache/query_api.rb +1 -1
- data/lib/identity_cache/version.rb +1 -1
- data/test/denormalized_has_many_test.rb +12 -20
- data/test/normalized_has_many_test.rb +4 -6
- 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: e1ebdc0142ea9597f6053f9d07ef1c43bfbd5434
|
4
|
+
data.tar.gz: 4aacba1f352ff488dc13cf4eadb136369c5cb767
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a46686540738897cc446dda713c3d99dcb8c7fd513351894d7ac3ae3ee43c46baac0648eb0876cb1db1e5b2bfacf1ee2e8586b3aeb055d6126479794fd797dfa
|
7
|
+
data.tar.gz: 40af995454fc23abaddcab686808a62972758d586f6a4514314a0b30730fac71accbfd83cd671a9e90553dc5daa45a30ab162c21680e76b9691697e9bb8f7707
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# IdentityCache changelog
|
2
2
|
|
3
|
+
#### 0.4.0
|
4
|
+
|
5
|
+
- Return an array from fetched association to prevent chaining. Up to now, a relation was returned by default. (#287)
|
6
|
+
|
3
7
|
#### 0.3.2
|
4
8
|
|
5
9
|
- Deprecate returning non read-only records when cache is used. Set IdentityCache.fetch_readonly_records to true to avoid this. (#282)
|
data/dev.yml
CHANGED
data/lib/identity_cache.rb
CHANGED
@@ -42,22 +42,17 @@ module IdentityCache
|
|
42
42
|
|
43
43
|
version = Gem::Version.new(IdentityCache::VERSION)
|
44
44
|
|
45
|
-
# fetch_#{association} for a cache_has_many association returns a relation
|
46
|
-
# when fetch_returns_relation is set to true and an array when set to false.
|
47
|
-
mattr_accessor :fetch_returns_relation
|
48
|
-
self.fetch_returns_relation = version < Gem::Version.new("0.4")
|
49
|
-
|
50
45
|
# Inverse active record associations are set when loading embedded
|
51
46
|
# cache_has_many associations from the cache when never_set_inverse_association
|
52
47
|
# is false. When set to true, it will only set the inverse cached association.
|
53
48
|
mattr_accessor :never_set_inverse_association
|
54
|
-
self.never_set_inverse_association = version >= Gem::Version.new("0.
|
49
|
+
self.never_set_inverse_association = version >= Gem::Version.new("0.5")
|
55
50
|
|
56
51
|
# Fetched records are not read-only and this could sometimes prevent IDC from
|
57
52
|
# reflecting what's truly in the database when fetch_read_only_records is false.
|
58
53
|
# When set to true, it will only return read-only records when cache is used.
|
59
54
|
mattr_accessor :fetch_read_only_records
|
60
|
-
self.fetch_read_only_records = version >= Gem::Version.new("0.
|
55
|
+
self.fetch_read_only_records = version >= Gem::Version.new("0.5")
|
61
56
|
|
62
57
|
def included(base) #:nodoc:
|
63
58
|
raise AlreadyIncludedError if base.include?(IdentityCache::ConfigurationDSL)
|
@@ -150,14 +145,6 @@ module IdentityCache
|
|
150
145
|
result
|
151
146
|
end
|
152
147
|
|
153
|
-
def with_fetch_returns_relation(value = true)
|
154
|
-
previous_value = self.fetch_returns_relation
|
155
|
-
self.fetch_returns_relation = value
|
156
|
-
yield
|
157
|
-
ensure
|
158
|
-
self.fetch_returns_relation = previous_value
|
159
|
-
end
|
160
|
-
|
161
148
|
def with_never_set_inverse_association(value = true)
|
162
149
|
old_value = self.never_set_inverse_association
|
163
150
|
self.never_set_inverse_association = value
|
@@ -236,11 +236,7 @@ module IdentityCache
|
|
236
236
|
if IdentityCache.should_use_cache? && !#{association}.loaded?
|
237
237
|
@#{options[:records_variable_name]} ||= #{options[:association_reflection].klass}.fetch_multi(#{options[:cached_ids_name]})
|
238
238
|
else
|
239
|
-
|
240
|
-
#{association}
|
241
|
-
else
|
242
|
-
#{association}.to_a
|
243
|
-
end
|
239
|
+
#{association}.to_a
|
244
240
|
end
|
245
241
|
end
|
246
242
|
|
@@ -12,12 +12,9 @@ class DenormalizedHasManyTest < IdentityCache::TestCase
|
|
12
12
|
@record.reload
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
|
17
|
-
|
18
|
-
record_from_db = Item.find(@record.id)
|
19
|
-
assert_equal Array, record_from_db.fetch_associated_records.class
|
20
|
-
end
|
15
|
+
def test_uncached_record_from_the_db_should_come_back_with_association_array
|
16
|
+
record_from_db = Item.find(@record.id)
|
17
|
+
assert_equal Array, record_from_db.fetch_associated_records.class
|
21
18
|
end
|
22
19
|
|
23
20
|
def test_uncached_record_from_the_db_will_use_normal_association
|
@@ -30,15 +27,12 @@ class DenormalizedHasManyTest < IdentityCache::TestCase
|
|
30
27
|
assert_equal expected, record_from_db.fetch_associated_records
|
31
28
|
end
|
32
29
|
|
33
|
-
def
|
34
|
-
|
35
|
-
assert_equal IdentityCache.fetch_returns_relation, false
|
36
|
-
Item.fetch(@record.id) # warm cache
|
30
|
+
def test_on_cache_hit_record_should_come_back_with_cached_association_array
|
31
|
+
Item.fetch(@record.id) # warm cache
|
37
32
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
33
|
+
record_from_cache_hit = Item.fetch(@record.id)
|
34
|
+
assert_equal @record, record_from_cache_hit
|
35
|
+
assert_equal Array, record_from_cache_hit.fetch_associated_records.class
|
42
36
|
end
|
43
37
|
|
44
38
|
def test_on_cache_hit_record_should_come_back_with_cached_association
|
@@ -113,12 +107,10 @@ class DenormalizedHasManyTest < IdentityCache::TestCase
|
|
113
107
|
child.save!
|
114
108
|
end
|
115
109
|
|
116
|
-
def
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
Item.transaction { check.call }
|
121
|
-
end
|
110
|
+
def test_fetch_association_does_not_allow_chaining
|
111
|
+
check = proc { assert_equal false, Item.fetch(@record.id).fetch_associated_records.respond_to?(:where) }
|
112
|
+
2.times { check.call } # for miss and hit
|
113
|
+
Item.transaction { check.call }
|
122
114
|
end
|
123
115
|
|
124
116
|
def test_never_set_inverse_association_on_cache_hit
|
@@ -197,12 +197,10 @@ class NormalizedHasManyTest < IdentityCache::TestCase
|
|
197
197
|
@not_cached.save!
|
198
198
|
end
|
199
199
|
|
200
|
-
def
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
Item.transaction { check.call }
|
205
|
-
end
|
200
|
+
def test_fetch_association_does_not_allow_chaining
|
201
|
+
check = proc { assert_equal false, Item.fetch(@record.id).fetch_associated_records.respond_to?(:where) }
|
202
|
+
2.times { check.call } # for miss and hit
|
203
|
+
Item.transaction { check.call }
|
206
204
|
end
|
207
205
|
|
208
206
|
def test_returned_records_should_be_readonly_on_cache_hit
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: identity_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Camilo Lopez
|
@@ -14,7 +14,7 @@ authors:
|
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
|
-
date:
|
17
|
+
date: 2017-02-02 00:00:00.000000000 Z
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
20
|
name: ar_transaction_changes
|