2009年8月24日月曜日

[Rails][CodeReading] Rails::Initializer (12) initialize_cache

Initializer.process で12番目に呼ばれる initialize_cache メソッド。

def initialize_cache
unless defined?(RAILS_CACHE)
silence_warnings { Object.const_set "RAILS_CACHE", ActiveSupport::Cache.lookup_store(configuration.cache_store) }

if RAILS_CACHE.respond_to?(:middleware)
# Insert middleware to setup and teardown local cache for each request
configuration.middleware.insert_after(:"ActionController::Failsafe", RAILS_CACHE.middleware)
end
end
end


メソッド名からしてキャッシュの初期化をしているのでしょうが、歯が立たず。
RAILS_CACHE.respond_to? という文からわかるように、RAILS_CACHEという変数にはクラスオブジェクトが入るはず。consoleでみてみると、
$ script/console 
>> p RAILS_CACHE
#<ActiveSupport::Cache::MemoryStore:0x890a8b4 @data={}>

と出ました。デフォルトではActiveSupport::Cache::MomoryStoreを使うらしい。

[Rails][CodeReading] Railsの初期化コードを読む (イントロ&目次)

0 件のコメント:

コメントを投稿