Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source
Show
Ignore:
Timestamp:
12/15/07 01:35:55 (1 year ago)
Author:
david
Message:

The initial, rough batch of work

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/2-1-caching/railties/lib/initializer.rb

    r8301 r8393  
    5959 
    6060    # Sequentially step through all of the available initialization routines, 
    61     # in order: 
    62     # 
    63     # * #check_ruby_version 
    64     # * #set_load_path 
    65     # * #require_frameworks 
    66     # * #set_autoload_paths 
    67     # * add_plugin_load_paths 
    68     # * #load_environment 
    69     # * #initialize_encoding 
    70     # * #initialize_database 
    71     # * #initialize_logger 
    72     # * #initialize_framework_logging 
    73     # * #initialize_framework_views 
    74     # * #initialize_dependency_mechanism 
    75     # * #initialize_whiny_nils 
    76     # * #initialize_temporary_directories 
    77     # * #initialize_framework_settings 
    78     # * #add_support_load_paths 
    79     # * #load_plugins 
    80     # * #load_observers 
    81     # * #initialize_routing 
    82     # * #after_initialize 
    83     # * #load_application_initializers 
     61    # in order (view execution order in source). 
    8462    def process 
    8563      check_ruby_version 
     
    9371      initialize_encoding 
    9472      initialize_database 
     73 
     74      initialize_cache 
     75      initialize_framework_caches 
     76 
    9577      initialize_logger 
    9678      initialize_framework_logging 
     79 
    9780      initialize_framework_views 
    9881      initialize_dependency_mechanism 
    9982      initialize_whiny_nils 
    100       initialize_temporary_directories 
     83      initialize_temporary_session_directory 
    10184      initialize_framework_settings 
    10285 
     
    236219    end 
    237220 
     221    def initialize_cache 
     222      unless defined?(RAILS_CACHE) 
     223        silence_warnings { Object.const_set "RAILS_CACHE", ActiveSupport::Cache.lookup_store(configuration.cache_store) } 
     224      end 
     225    end 
     226 
     227    def initialize_framework_caches 
     228      if configuration.frameworks.include?(:action_controller) 
     229        ActionController::Base.cache_store ||= RAILS_CACHE 
     230      end 
     231    end 
     232 
    238233    # If the +RAILS_DEFAULT_LOGGER+ constant is already set, this initialization 
    239234    # routine does nothing. If the constant is not set, and Configuration#logger 
     
    274269        framework.to_s.camelize.constantize.const_get("Base").logger ||= RAILS_DEFAULT_LOGGER 
    275270      end 
     271       
     272      RAILS_CACHE.logger ||= RAILS_DEFAULT_LOGGER 
    276273    end 
    277274 
     
    306303    end 
    307304 
    308     def initialize_temporary_directories 
     305    def initialize_temporary_session_directory 
    309306      if configuration.frameworks.include?(:action_controller) 
    310307        session_path = "#{configuration.root_path}/tmp/sessions/" 
    311308        ActionController::Base.session_options[:tmpdir] = File.exist?(session_path) ? session_path : Dir::tmpdir 
    312  
    313         cache_path = "#{configuration.root_path}/tmp/cache/" 
    314         if File.exist?(cache_path) 
    315           ActionController::Base.fragment_cache_store = :file_store, cache_path 
    316         end 
    317309      end 
    318310    end 
     
    414406    # used directly. 
    415407    attr_accessor :logger 
     408 
     409    # The specific cache store to use. By default, the ActiveSupport::Cache::Store will be used. 
     410    attr_accessor :cache_store 
    416411 
    417412    # The root of the application's views. (Defaults to <tt>app/views</tt>.) 
     
    644639        Plugin::Loader 
    645640      end 
     641       
     642      def default_cache_store 
     643        if File.exist?("#{root_path}/tmp/cache/") 
     644          [ :file_store, "#{root_path}/tmp/cache/" ] 
     645        else 
     646          :memory_store 
     647        end 
     648      end 
    646649  end 
    647650end