identity_cache 0.4.1 → 0.5.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: 1fa182ed254be40433e84f2bdef8faf341581e5f
4
- data.tar.gz: b795a7e03b4cf94a9d5ff3fd77e04186cde84d5c
3
+ metadata.gz: 11bd2d6f14e2b77b00c8bd58dd0731fa2976a81a
4
+ data.tar.gz: 4d547e1b739ce13b443dfb9ea44416a81936ed95
5
5
  SHA512:
6
- metadata.gz: 51c4645eb6a548c720444d6964412576bf9c84a399ad1a100251953d24f7e114654170eb4ae3111c906fedd1d9f0555c1c3c2734904675383f84f9ee62fe3362
7
- data.tar.gz: fabf846eb3ac2d9ccd9eda7f11dc3e42ed64ac5b678863fd1755e066bc04fc77cc46c4cf9eade1149da4a7fa244c28a45a62fdd4c798501a0b3764ded56d697f
6
+ metadata.gz: 63aa5192013b0d99b426e0b1cf70ea6962924a57da29beaac507b4d5dae458693822a55cd24bc743768826d7b725592b456c0ca68cc9655df5509100a0ab68b3
7
+ data.tar.gz: 99cab0e7c1b4d8a4a5378b408582486404182e86529d4e62926d29ab3c021a2ff9af02a4af05d0a5eae4cd6996a76f4588a4e03584645025d7c7131a122407fd
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # IdentityCache changelog
2
2
 
3
+ #### 0.5.0
4
+
5
+ - `never_set_inverse_association` and `fetch_read_only_records` are now `true` by default (#315)
6
+ - Store the class name instead of the class itself (#311)
7
+
3
8
  #### 0.4.1
4
9
 
5
10
  - Deprecated embedded associations on models that don't use IDC (#305)
@@ -53,19 +53,17 @@ module IdentityCache
53
53
  mattr_accessor :cache_namespace
54
54
  self.cache_namespace = "IDC:#{CACHE_VERSION}:".freeze
55
55
 
56
- version = Gem::Version.new(IdentityCache::VERSION)
57
-
58
56
  # Inverse active record associations are set when loading embedded
59
57
  # cache_has_many associations from the cache when never_set_inverse_association
60
58
  # is false. When set to true, it will only set the inverse cached association.
61
59
  mattr_accessor :never_set_inverse_association
62
- self.never_set_inverse_association = version >= Gem::Version.new("0.5")
60
+ self.never_set_inverse_association = true
63
61
 
64
62
  # Fetched records are not read-only and this could sometimes prevent IDC from
65
63
  # reflecting what's truly in the database when fetch_read_only_records is false.
66
64
  # When set to true, it will only return read-only records when cache is used.
67
65
  mattr_accessor :fetch_read_only_records
68
- self.fetch_read_only_records = version >= Gem::Version.new("0.5")
66
+ self.fetch_read_only_records = true
69
67
 
70
68
  def included(base) #:nodoc:
71
69
  raise AlreadyIncludedError if base.respond_to?(:cached_model)
@@ -122,7 +122,7 @@ module IdentityCache
122
122
 
123
123
  def record_from_coder(coder) #:nodoc:
124
124
  if coder
125
- klass = coder[:class]
125
+ klass = coder[:class].constantize
126
126
  record = klass.instantiate(coder[:attributes].dup)
127
127
 
128
128
  coder[:associations].each {|name, value| set_embedded_association(record, name, value) } if coder.has_key?(:associations)
@@ -179,7 +179,7 @@ module IdentityCache
179
179
  unless record.nil?
180
180
  coder = {
181
181
  attributes: record.attributes_before_type_cast.dup,
182
- class: record.class,
182
+ class: record.class.name,
183
183
  }
184
184
  add_cached_associations_to_coder(record, coder)
185
185
  coder
@@ -1,4 +1,4 @@
1
1
  module IdentityCache
2
- VERSION = "0.4.1"
3
- CACHE_VERSION = 6
2
+ VERSION = "0.5.0"
3
+ CACHE_VERSION = 7
4
4
  end
@@ -130,12 +130,15 @@ class DenormalizedHasManyTest < IdentityCache::TestCase
130
130
  end
131
131
 
132
132
  def test_deprecated_set_inverse_association_on_cache_hit
133
+ IdentityCache.never_set_inverse_association = false
133
134
  Item.fetch(@record.id) # warm cache
134
135
 
135
136
  item = Item.fetch(@record.id)
136
137
 
137
138
  associated_record = item.fetch_associated_records.to_a.first
138
139
  assert_equal item.object_id, associated_record.item.object_id
140
+ ensure
141
+ IdentityCache.never_set_inverse_association = true
139
142
  end
140
143
 
141
144
  def test_returned_records_should_be_readonly_on_cache_hit
@@ -286,7 +286,7 @@ class FetchMultiTest < IdentityCache::TestCase
286
286
  end
287
287
 
288
288
  def cache_response_for(record)
289
- {class: record.class, attributes: record.attributes_before_type_cast}
289
+ { class: record.class.name, attributes: record.attributes_before_type_cast }
290
290
  end
291
291
 
292
292
  def with_batch_size(size)
data/test/fetch_test.rb CHANGED
@@ -11,7 +11,7 @@ class FetchTest < IdentityCache::TestCase
11
11
  @record = Item.new
12
12
  @record.id = 1
13
13
  @record.title = 'bob'
14
- @cached_value = {class: @record.class, attributes: @record.attributes_before_type_cast}
14
+ @cached_value = { class: @record.class.name, attributes: @record.attributes_before_type_cast }
15
15
  @blob_key = "#{NAMESPACE}blob:Item:#{cache_hash("created_at:datetime,id:integer,item_id:integer,title:string,updated_at:datetime")}:1"
16
16
  @index_key = "#{NAMESPACE}attr:Item:id:title:#{cache_hash('bob')}"
17
17
  end
Binary file
@@ -20,7 +20,16 @@ module SerializationFormat
20
20
  end
21
21
  record.reload
22
22
  Item.fetch(record.id)
23
- IdentityCache.fetch(record.primary_cache_index_key)
23
+
24
+ IdentityCache.fetch(record.primary_cache_index_key) do
25
+ STDERR.puts(
26
+ "\e[31m" \
27
+ "The record could not be retrieved from the cache." \
28
+ "Did you configure MEMCACHED_HOST?" \
29
+ "\e[0m",
30
+ )
31
+ exit(1)
32
+ end
24
33
  end
25
34
 
26
35
  def serialized_record_file
@@ -16,7 +16,10 @@ DatabaseConnection.setup
16
16
  DatabaseConnection.drop_tables
17
17
  DatabaseConnection.create_tables
18
18
  IdentityCache.logger = Logger.new(nil)
19
- IdentityCache.cache_backend = ActiveSupport::Cache::MemcachedStore.new("localhost:11211", :support_cas => true)
19
+ IdentityCache.cache_backend = ActiveSupport::Cache::MemcachedStore.new(
20
+ "#{ENV["MEMCACHED_HOST"] || "localhost"}:11211",
21
+ :support_cas => true,
22
+ )
20
23
  setup_models
21
24
  File.open(serialized_record_file, 'w') {|file| serialize(serialized_record, file) }
22
25
  puts "Serialized record to #{serialized_record_file}"
@@ -1,6 +1,16 @@
1
1
  require "test_helper"
2
2
 
3
3
  class MemoizedAttributesTest < IdentityCache::TestCase
4
+ def setup
5
+ IdentityCache.fetch_read_only_records = false
6
+ super
7
+ end
8
+
9
+ def teardown
10
+ super
11
+ IdentityCache.fetch_read_only_records = true
12
+ end
13
+
4
14
  def test_memoization_should_not_break_dirty_tracking_with_empty_cache
5
15
  item = Item.create!
6
16
 
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.1
4
+ version: 0.5.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: 2017-02-02 00:00:00.000000000 Z
17
+ date: 2017-02-07 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: ar_transaction_changes
@@ -270,7 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
270
270
  version: '0'
271
271
  requirements: []
272
272
  rubyforge_project:
273
- rubygems_version: 2.5.1
273
+ rubygems_version: 2.5.2
274
274
  signing_key:
275
275
  specification_version: 4
276
276
  summary: IdentityCache lets you specify how you want to cache your model objects,