ngmoco / cache-money

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

Uncacheable entries for very basic finds #7

Closed rwygand closed 14 years ago

rwygand commented 14 years ago

I'm evaluating cache-money for possible uses and it looks completely awesome, but I'm seeing an issue I don't understand. Essentially, records I'd expect to be indexed aren't being indexed. Here's the code where the query comes from:

User.find(session['user'])

and in the server logs I see

UNCACHEABLE users - {:conditions=>{:id=>100001721}} - {} - {} - {}

I was under the impression I would not need to specify an index for primary keys, but I've also tried this with the same result: no caching. What must I be doing incorrectly?

rwygand commented 14 years ago

Interesting.

I seem to have resolved this by enabling automatic_caching in cache_money.rb via memcached.yml. Previously, I was specifying ' is_cached :repository => $cache' in each model I wanted cached, but this was not working, as stated above.

rwygand commented 14 years ago

I believe I found it. abstract.rb calls @active_record.cachable? which is defined in the NoCash module in cache_money.rb. But the mirror function, in the CashMoney module is spelled 'cacheable' with an 'e'. This means that even if you set is_cached in your model, you will always call NoCash::cachable.

ashleym1972 commented 14 years ago

Do you have a diff?

rwygand commented 14 years ago

Sure do:

http://github.com/rwygand/cache-money/commit/ed2223a6e156a2bff9fdebc97f52ac122334ccb0

ashleym1972 commented 14 years ago

Successfully registered gem: ngmoco-cache-money (0.2.21)