Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 2230

Show
Ignore:
Timestamp:
09/13/05 08:31:32 (3 years ago)
Author:
david
Message:

Added easy assignment of fragment cache store through use of symbols for included stores (old way still works too)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r2228 r2230  
    11*SVN* 
     2 
     3* Added easy assignment of fragment cache store through use of symbols for included stores (old way still works too) 
     4 
     5  Before: 
     6    ActionController::Base.fragment_cache_store =  
     7      ActionController::Base::Caching::Fragments::FileStore.new("/path/to/cache/directory") 
     8 
     9  After: 
     10    ActionController::Base.fragment_cache_store = :file_store, "/path/to/cache/directory" 
    211 
    312* Added ActionController::Base.session_store=, session_store, and session_options to make it easier to tweak the session options (instead of going straight to ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS) 
  • trunk/actionpack/lib/action_controller.rb

    r2191 r2230  
    3939require 'action_controller/layout' 
    4040require 'action_controller/flash' 
    41 require 'action_controller/session' 
    4241require 'action_controller/dependencies' 
    4342require 'action_controller/pagination' 
     
    6867  include ActionController::Helpers 
    6968  include ActionController::Cookies 
    70   include ActionController::Session 
    7169  include ActionController::Caching 
    7270  include ActionController::Components 
  • trunk/actionpack/lib/action_controller/caching.rb

    r2142 r2230  
    241241    # Configuration examples (MemoryStore is the default): 
    242242    # 
    243     #   ActionController::Base.fragment_cache_store =  
    244     #     ActionController::Caching::Fragments::MemoryStore.new 
    245     # 
    246     #   ActionController::Base.fragment_cache_store =  
    247     #     ActionController::Caching::Fragments::FileStore.new("/path/to/cache/directory") 
    248     # 
    249     #   ActionController::Base.fragment_cache_store =  
    250     #     ActionController::Caching::Fragments::DRbStore.new("druby://localhost:9192") 
    251     # 
    252     #   ActionController::Base.fragment_cache_store =  
    253     #     ActionController::Caching::Fragments::MemCacheStore.new("localhost") 
     243    #   ActionController::Base.fragment_cache_store = :memory_store 
     244    #   ActionController::Base.fragment_cache_store = :file_store, "/path/to/cache/directory" 
     245    #   ActionController::Base.fragment_cache_store = :drb_store, "druby://localhost:9192" 
     246    #   ActionController::Base.fragment_cache_store = :mem_cache_store, "localhost" 
     247    #   ActionController::Base.fragment_cache_store = MyOwnStore.new("parameter") 
    254248    module Fragments 
    255249      def self.append_features(base) #:nodoc: 
     
    257251        base.class_eval do 
    258252          @@fragment_cache_store = MemoryStore.new 
    259           cattr_accessor :fragment_cache_store 
     253          cattr_reader :fragment_cache_store 
     254 
     255          def self.fragment_cache_store=(store_option) 
     256            store, *parameters = *([ store_option ].flatten) 
     257            @@fragment_cache_store = if store.is_a?(Symbol) 
     258              store_class_name = (store == :drb_store ? "DRbStore" : store.to_s.camelize) 
     259              store_class = ActionController::Caching::Fragments.const_get(store_class_name) 
     260              parameters.empty? ? store.new : store_class.new(*parameters) 
     261            else 
     262              store 
     263            end 
     264          end 
    260265        end 
    261266      end 
     
    350355 
    351356      class DRbStore < MemoryStore #:nodoc: 
     357        attr_reader :address 
     358 
    352359        def initialize(address = 'druby://localhost:9192') 
     360          @address = address 
    353361          @data, @mutex = DRbObject.new(nil, address), Mutex.new 
    354362        end     
     
    356364 
    357365      class MemCacheStore < MemoryStore #:nodoc: 
     366        attr_reader :address 
     367 
    358368        def initialize(address = 'localhost') 
     369          @address = address 
    359370          @data, @mutex = MemCache.new(address), Mutex.new 
    360371        end     
     
    362373 
    363374      class FileStore #:nodoc: 
     375        attr_reader :cache_path 
     376         
    364377        def initialize(cache_path) 
    365378          @cache_path = cache_path 
  • trunk/actionpack/lib/action_controller/cgi_process.rb

    r2151 r2230  
    22require 'action_controller/cgi_ext/cookie_performance_fix' 
    33require 'action_controller/cgi_ext/raw_post_data_fix' 
    4 require 'action_controller/session/drb_store' 
    5 require 'action_controller/session/mem_cache_store' 
    6 if Object.const_defined?(:ActiveRecord) 
    7   require 'action_controller/session/active_record_store' 
    8 end 
    94 
    105module ActionController #:nodoc: 
  • trunk/actionpack/lib/action_controller/session_management.rb

    r2229 r2230  
     1require 'action_controller/session/drb_store' 
     2require 'action_controller/session/mem_cache_store' 
     3if Object.const_defined?(:ActiveRecord) 
     4  require 'action_controller/session/active_record_store' 
     5end 
     6 
    17module ActionController #:nodoc: 
    28  module SessionManagement #:nodoc: 
     
    410      super 
    511      base.extend(ClassMethods) 
    6       base.class_eval do 
    7         alias_method :process_without_session_management_support, :process 
    8         alias_method :process, :process_with_session_management_support 
    9       end 
     12      base.send(:alias_method, :process_without_session_management_support, :process) 
     13      base.send(:alias_method, :process, :process_with_session_management_support) 
     14      base.after_filter(:clear_persistant_model_associations) 
    1015    end 
    1116 
     
    1621      def session_store=(store) 
    1722        ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS[:database_manager] = 
    18           store.is_a?(Symbol) ? CGI::Session.const_get(store.to_s.camelize) : store 
     23          store.is_a?(Symbol) ? CGI::Session.const_get(store == :drb_store ? "DRbStore" : store.to_s.camelize) : store 
    1924      end 
    2025 
     
    101106      process_without_session_management_support(request, response, method, *arguments) 
    102107    end 
     108   
     109    private 
     110      def clear_persistant_model_associations #:doc: 
     111        session = @session.instance_variable_get("@data") 
     112        session.each { |key, obj| obj.clear_association_cache if obj.respond_to?(:clear_association_cache) } if session 
     113      end 
    103114  end 
    104115end 
  • trunk/actionpack/test/controller/session_management_test.rb

    r2031 r2230  
    8282    assert_equal false, @request.session_options 
    8383  end 
     84   
     85  def test_session_store_setting 
     86    ActionController::Base.session_store = :drb_store 
     87    assert_equal CGI::Session::DRbStore, ActionController::Base.session_store 
     88 
     89    if Object.const_defined?(:ActiveRecord) 
     90      ActionController::Base.session_store = :active_record_store 
     91      assert_equal CGI::Session::ActiveRecordStore, ActionController::Base.session_store 
     92    end 
     93  end 
    8494end