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 calls as_json (at this point, the cache is accurate)
- Process B updates field
:b and calls as_json (at this point, a stale value of :a replaced the accurate value)
Or, in a console:
j1 = User.find_by_email('joey@example.com')
# => #<User ...>
j2 = User.find_by_email('joey@example.com')
# => #<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('joey@example.com').as_json(properties: :all)[:phone]
# => "646-338-3382"
User.find_by_email('joey@example.com').phone
# => "800-foo-barz"
In the simplest case, imagine 2 jobs or requests are updating different fields of the same document.
:aand callsas_json(at this point, the cache is accurate):band callsas_json(at this point, a stale value of:areplaced the accurate value)Or, in a console: