毎回同じDBアクセスの場合キャッシュしたくなりますよね。
今日はちょっと感動したコードを紹介。
Rails高速化にはこういうテクニックが必要ですなぁ。
class Area < ActiveRecord::Base@@cache = nil
class << self
def find_default_area()
unless @@cache
@@cache = find(:all,:conditions....)
end
return @@cache
end
endend
クラス変数にこういう形で使うとはなるほど、と思いました。