Skip to content

Stale data overwrites good data if object has been updated since it was loaded #19

Open
@joeyAghion

Description

@joeyAghion

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('[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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions