Will it work with the problem of updating two users?
I googled and looked in the api but found nothing
Rails 3+, ruby 1.9.3
When using counter_cache, writing and updating the counter are performed in one transaction. But this does not guarantee the atomicity of the operation. You may need to “lock” your account to avoid problems updating two users.
See this great article . This is about the redis-objects stone, but the first two parts perfectly explain the problem and solution using ActiveRecord.
: . , Rails counter_cache , , , , , , , , with_lock .
counter_cache
with_lock