Open
Description
In the simplest case, imagine 2 jobs or requests are updating different fields of the same document.
- Processes A and B both load the document into memory
- Process A updates field
:a
and callsas_json
(at this point, the cache is accurate) - Process B updates field
:b
and callsas_json
(at this point, a stale value of:a
replaced the accurate value)
Or, in a console:
j1 = User.find_by_email('[email protected]')
# => #<User ...>
j2 = User.find_by_email('[email protected]')
# => #<User ...>
j1.phone
# => "646-338-3382"
j1.as_json(properties: :all)[:phone]
# => "646-338-3382"
j2.phone
# => "646-338-3382"
j2.phone = '800-foo-barz'
# => "800-foo-barz"
j2.save!
# => true
j2.as_json(properties: :all)[:phone]
# => "800-foo-barz"
j1.profession = 'chimney sweep'
# => "chimney sweep"
j1.save!
# => true
j1.as_json(properties: :all)[:phone]
# => "646-338-3382"
User.find_by_email('[email protected]').as_json(properties: :all)[:phone]
# => "646-338-3382"
User.find_by_email('[email protected]').phone
# => "800-foo-barz"