using acts_as_cached and cached_model together

12 views
Skip to first unread message

Rob Sanheim

unread,
Feb 21, 2007, 1:52:55 PM2/21/07
to acts_as...@googlegroups.com
Is it possible for acts_as_cached and cached_model to work together
w/o stepping on each others toes in the same app? I have some models
where just having the very simple, find by id queries cached would be
helpful (w/ cached_model), but would also benefit from having some
complex queries cached w/ aac.

I'm just getting up to speed w/ memcached strategies in rails, so this
might be crazy talk. Just wanted to throw this out there...

- Rob

Chris Wanstrath

unread,
Feb 21, 2007, 8:17:24 PM2/21/07
to acts_as...@googlegroups.com
On 2/21/07, Rob Sanheim <rsan...@gmail.com> wrote:

> Is it possible for acts_as_cached and cached_model to work together
> w/o stepping on each others toes in the same app? I have some models
> where just having the very simple, find by id queries cached would be
> helpful (w/ cached_model), but would also benefit from having some
> complex queries cached w/ aac.

Looking through the source, I think both acts_as_cached and
CachedModel implement a 'cache_store' method. That could cause
problems.

The new version of acts_as_cached, cache_fu, should work with it no
problem (as all the internal methods, like cache_store, are maintained
in a cleaner fashion). I'm hoping to announce the new version with
documentation within the next few weeks.

The only real issue would be if you called get_cache on a single
record, which in turn calls find, which is overridden by CachedModel
to sekritly cache.

> I'm just getting up to speed w/ memcached strategies in rails, so this
> might be crazy talk. Just wanted to throw this out there...

I'd be curious to hear what the perceived benefit of CachedModel is.
As far as I know, you can accomplish the same thing using aac simply
without subclassing or overriding find:

class Something < ActiveRecord::Base
after_update :expire_cache
end

>> Something.get_cache(1)
=> < cached or found object >

It may do other things I'm not familiar with, as I only used it
briefly (and, at this point, many moons ago).

Thanks.

--
Chris Wanstrath
http://errtheblog.com

Rob Sanheim

unread,
Mar 5, 2007, 5:02:43 PM3/5/07
to acts_as...@googlegroups.com
Hi Chris,

Now that I've spent some time implementing cache_fu, I agree that I
don't need cached_model. My initial thinking was cached_model would
be nice for the simplest case, but now that I've seen how nicely
cache_fu works I'm just going to stick with that. Its better to have
the consistent, explicit approach then trying to mix two plugins.

Do you have any updates or plans on when cache_fu will be come the
official AAC? Also, I'd love to hear from other users on typical
idioms they are using.

- Rob

Chris Wanstrath

unread,
Mar 6, 2007, 3:42:59 PM3/6/07
to acts_as...@googlegroups.com
On 3/5/07, Rob Sanheim <rsan...@gmail.com> wrote:

> Now that I've spent some time implementing cache_fu, I agree that I
> don't need cached_model. My initial thinking was cached_model would
> be nice for the simplest case, but now that I've seen how nicely
> cache_fu works I'm just going to stick with that. Its better to have
> the consistent, explicit approach then trying to mix two plugins.

Cool.

> Do you have any updates or plans on when cache_fu will be come the
> official AAC? Also, I'd love to hear from other users on typical
> idioms they are using.

Whenever I get around to writing all the documentation. It is more or
less feature complete (there's some experimental stuff I haven't
gotten around to implementing), but I wouldn't feel right releasing it
without a solid howoto and doc site.

Yes, handy idioms from people would be fantastic...

Reply all
Reply to author
Forward
0 new messages