-
Notifications
You must be signed in to change notification settings - Fork 31
Description
Hello,
I have a Person model with a name attribute, and that model is cached normally by its id.
When I type in the following I can consistently produce stale results with cache_money:
$ script/console
>> p = Person.find_all_by_id([1, 2]).first
>> p.name
=> "Al Bundy"
>> p.name = "Alice Bundy"
>> p.save!
>> Person.find_all_by_id([1]).first.name
=> "Alice Bundy"
>> Person.find_all_by_id([1, 2]).first.name
=> "Al Bundy"
If you run memcached with verbose on, you will see entries like:
<28 get dev_cache:Person:1/id/1/2
<28 add dev_cache:Person:1/id/1/2 0 86400 1062
<28 get dev_cache:Person:1/id/1
<28 add dev_cache:Person:1/id/1 0 86400 729
<28 add dev_cache:lock/Person:1/id/1 0 30 6
<28 set dev_cache:Person:1/id/1 0 86400 948
<28 delete dev_cache:lock/Person:1/id/1 0
<28 get dev_cache:Person:1/id/1/2
>28 sending key dev_cache:Person:1/id/1/2
So with find_by_ids([1,2]) the resulting 2 objects are stored together using cache_key "Person:1/id/1/2". And when the name of the Person with ID 1 is updated, only the cache_key with the single object "Person:1/id/1" is updated.
This looks like a major flaw in cache_money. Am I missing something, or do other people experience the same issue?
Kind regards,
orslumen.