ngmoco / cache-money

A Write-Through Cacheing Library for ActiveRecord
Apache License 2.0
161 stars 31 forks source link

Transactional race condition #15

Closed betamatt closed 13 years ago

betamatt commented 13 years ago

We're tracking an issue with a race condition in cache-money. It should only affect people who use a combination of cached and uncached models.

The issue occurs because transactional updates are written to cache before the database transaction commits. In our case, we have a cached parent model with an uncached collection. The parent and collection are updated in a transaction but due to the parent being cached, the update to that record is visible to other requests before the dependent collection updates.

Two solutions appear to be

  1. make sure all involved records are cached
  2. wrap the database transaction in another cache transaction so that the cache buffer is only flushed after the database commits
ashleym1972 commented 13 years ago

I merged it into master and develop. Working on a release.