This project is archived and is in readonly mode.
Allow to unmoemoize only specific method(s)
-
josh
- State changed from new to open
- Assigned user set to josh
I would recommend using the reload API instead of just clearing its cache.
foo(:reload) # or foo(true)Am I missing another use case?
-
Paweł Kondzior
In this example
foois memoized method ?Using unmemoize(:method1, :method2) can be useful when we want to override attribute setter which depends on our memoized methods, for AR we can override reload to unmemoize_all, but in such example we clear whole cache, even if we only need to clear one method.
class Foo < ActiveRecord::Base extend ActiveSupport::Memoizable def is_something_valid? if self.only_locations && Location.find(:all, :conditions => ['some_conditions'] true else false end end def only_locations=(value) unmemoize(:is_something_valid?) super(value) end memoize(:is_something_valid?) end -
Paweł Kondzior
Internally in Memoizable::Freezable i think it will be DRY to not repeat same code in unmemoizel_all and unmemoize. Obviously i don't know what internal policy Rails have, and it is really necessary to be DRY fundamentalist here.
-
josh
You sold me.
A few things though,
- Needs test case
- Like you said, build unmemoize_all on top of it. Maybe even make unmemoize_all just unmemoize(:all)
- I know we'd be changing old apis, but unmemoize isn't intention revealing. It sounds like is doing the opposite of the memoize helper and removing the ability permanently. I'd prefer something like "flush_cache".
-
Repository
- State changed from open to resolved
(from [761a633a9c0a45d76ef3ed10da97e3696c3ded79]) Add Memoizable#flush_cache to clear the cache of a specific method [#1505 Allow to unmoemoize only specific method(s) state:resolved] http://github.com/rails/rails/co...
-
Paweł Kondzior
I love it ;) Big thanks.
