In Files

Class Index [+]

Quicksearch

When::Parts::MethodCash

メソッドの実行結果をキャッシュし処理の高速化を行う

fn というメソッドをキャッシュ化

 * fn ではなく fn_ を定義しておく
 * fn メソッドが呼ばれると fn_ を実行し、{引数=>戻り値} を Hash に記憶する
 * 同じ引数で再度 fn メソッドが呼ばれると Hash から戻り値を取り出して返す

a_to_b と b_to_a という互いに逆関数のメソッドをキャッシュ化

 * a_to_b ではなく a_to_b_ , b_to_a ではなく b_to_a_ を定義しておく
 * a_to_b メソッドが呼ばれると a_to_b_ を実行し、{引数=>戻り値}, {戻り値=>引数}を Hash に記憶する
 * 同じ引数で再度 a_to_b メソッドが呼ばれると Hash から戻り値を取り出して返す
 * b_to_a メソッドが呼ばれ Hash に戻り値があれば Hash から戻り値を取り出して返す

特記事項

Argument identification

  The eql? method of When::TM::(Temporal)Position is not overridden.
  It seems that the cost of identification of the argument exceeds the merit of the method cash.
  I do not recommend applying the methodcash to the method which takes
  When::TM::(Temporal)Position as an argument.

Multi-thread critical situation

  There is a problem in consistency of hash when this function is used in multi-thread environment.
  If the initialize method sets Mutex in instance variable @_m_cash_lock_,
  this function gives up use of hash in the critical situation.

  class Foo
    include MethodCash

    def initialize
      ...
      @_m_cash_lock_ = Mutex.new
      ...
     end
  end

  参考 http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/47663

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.