Forum: Ruby on Rails Memoization on freeze

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9adf5654c4a418af20377e365c3334bb?d=identicon&s=25 Mike Grafton (Guest)
on 2008-12-06 21:46
(Received via mailing list)
Hey alI,

I like the new support for memoizable methods in Rails 2.2.  However,
I'm running into a problem that's making it hard to use in my case.

My ActiveRecord model has a method that does a lot of data crunching,
and it takes a few seconds.  I used ActiveSupport::Memoizable and
memoized that long-running method, which made my code quite clean
since I can call it willy-nilly from all over my view.  Very nice.

The problem happens when I call #destroy on the model.  I didn't know
much about freezing AR objects, so I was surprised when I found out
that #destroy called #freeze, and #freeze called #memoize_all.  This
calls my long-running method, sadly, which is about the last thing I
want to happen when destroying my object!

My work-around was to call ModelClass.delete(id), but that's kinda
lame given that it doesn't go through the normal callback cycle - it
will surely bite me on the ass someday.

Any other workaround to this problem I don't see?  Besides, of course,
rolling my own memoization?

Thanks!
Mike
A05834e9b5954947eb0ba3b570c47d5e?d=identicon&s=25 Pratik Naik (pratik)
on 2008-12-07 04:31
(Received via mailing list)
Hey Mike,

That looks a valid issue/bug. I've pinged Josh about it as he is the
guy in charge of memoization code.

Thanks!

On Sat, Dec 6, 2008 at 9:00 PM, Mike Grafton <mike@pivotallabs.com>
wrote:
>
> Any other workaround to this problem I don't see?  Besides, of course,
> rolling my own memoization?
>
> Thanks!
> Mike
>
> >
>



--
Cheers!
- Pratik
http://m.onkey.org
This topic is locked and can not be replied to.