This project is archived and is in readonly mode.
Allow to unmoemoize only specific method(s)
Reported by Paweł Kondzior | December 2nd, 2008 @ 12:04 PM | in 2.x
This patch will allow to unmemoize only specific methods, right now when you want to unmemoize something in instance of method, you must use unmemoize_all
Comments and changes to this ticket
-
josh December 3rd, 2008 @ 02:18 AM
- 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 December 3rd, 2008 @ 08:39 AM
In this example
foo
is 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 December 3rd, 2008 @ 08:43 AM
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 December 3rd, 2008 @ 03:18 PM
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 December 3rd, 2008 @ 04:57 PM
- State changed from open to resolved
(from [761a633a9c0a45d76ef3ed10da97e3696c3ded79]) Add Memoizable#flush_cache to clear the cache of a specific method [#1505 state:resolved] http://github.com/rails/rails/co...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 1505 Allow to unmoemoize only specific method(s) (from [761a633a9c0a45d76ef3ed10da97e3696c3ded79]) Add Mem...