ngmoco / cache-money

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

CacheMoney::Index#update( object ) hits database for every defined index #6

Closed sriedel closed 14 years ago

sriedel commented 14 years ago

The queries triggered per index do a where over the indexed attributes, causing multiple slow queries in the database if you're trying to have indices for cache money without indexing the same attributes in the database.

Intuitively, a design that fetches the object once for the index updates and updates each index with the values from that fetched object would be a more straight forward procedure.

Alternatively, invalidate all indices for a class on a write, and fetch the data for an index once that particular index is read.

ashleym1972 commented 14 years ago

I think you are missing the point of index. It is not a per object index; i.e. hey I loaded this object, let's stick it's "index" value in the hash. When you specify an index you say hey I'm interested in all values match x for field y and so cache-money performs that query and populates the cache with the results. It's the only way to guarantee that the cache is correct.