Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Allow to unmoemoize only specific method(s)

#1505

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

Reported by Paweł Kondzior · December 2nd, 2008 @ 12:04 PM

State: resolved
Milestone: 2.x
Assigned to: josh josh
Importance: none

Activity

  1. josh
    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?

    December 3rd, 2008 @ 02:18 AM

  2. Paweł Kondzior
    Paweł Kondzior

    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
    

    December 3rd, 2008 @ 08:39 AM

  3. Paweł Kondzior
    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.

    December 3rd, 2008 @ 08:43 AM

  4. josh
    josh

    You sold me.

    A few things though,

    1. Needs test case
    2. Like you said, build unmemoize_all on top of it. Maybe even make unmemoize_all just unmemoize(:all)
    3. 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".

    December 3rd, 2008 @ 03:18 PM

  5. Repository
    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...

    December 3rd, 2008 @ 04:57 PM

  6. Paweł Kondzior