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

Changeset 6868

Show
Ignore:
Timestamp:
05/27/07 16:38:02 (1 year ago)
Author:
david
Message:

Added custom path cache_page/expire_page parameters in addition to the options hashes [DHH]

Files:

Legend:

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

    r6867 r6868  
    11*SVN* 
     2 
     3* Added custom path cache_page/expire_page parameters in addition to the options hashes [DHH]. Example: 
     4 
     5    def index 
     6      caches_page(response.body, "/index.html") 
     7    end 
    28 
    39* Action Caching speedup.  #8231 [skaes] 
  • trunk/actionpack/lib/action_controller/caching.rb

    r6867 r6868  
    119119      def expire_page(options = {}) 
    120120        return unless perform_caching 
    121         if options[:action].is_a?(Array) 
    122           options[:action].dup.each do |action| 
    123             self.class.expire_page(url_for(options.merge(:only_path => true, :skip_relative_url_root => true, :action => action))) 
     121 
     122        if options.is_a?(Hash) 
     123          if options[:action].is_a?(Array) 
     124            options[:action].dup.each do |action| 
     125              self.class.expire_page(url_for(options.merge(:only_path => true, :skip_relative_url_root => true, :action => action))) 
     126            end 
     127          else 
     128            self.class.expire_page(url_for(options.merge(:only_path => true, :skip_relative_url_root => true))) 
    124129          end 
    125130        else 
    126           self.class.expire_page(url_for(options.merge(:only_path => true, :skip_relative_url_root => true))
     131          self.class.expire_page(options
    127132        end 
    128133      end 
     
    133138      def cache_page(content = nil, options = {}) 
    134139        return unless perform_caching && caching_allowed 
    135         self.class.cache_page(content || response.body, url_for(options.merge(:only_path => true, :skip_relative_url_root => true, :format => params[:format]))) 
     140         
     141        if options.is_a?(Hash) 
     142          path = url_for(options.merge(:only_path => true, :skip_relative_url_root => true, :format => params[:format])) 
     143        else 
     144          path = options 
     145        end 
     146         
     147        self.class.cache_page(content || response.body, path) 
    136148      end 
    137149 
  • trunk/actionpack/test/abstract_unit.rb

    r6740 r6868  
    99require 'action_controller/cgi_ext' 
    1010require 'action_controller/test_process' 
     11 
     12require 'ruby-debug' 
    1113 
    1214# Show backtraces for deprecated behavior for quicker cleanup. 
  • trunk/actionpack/test/controller/caching_test.rb

    r6867 r6868  
    2626    head :not_found 
    2727  end 
     28   
     29  def custom_path 
     30    render :text => "Super soaker" 
     31    cache_page("Super soaker", "/index.html") 
     32  end 
     33   
     34  def expire_custom_path 
     35    expire_page("/index.html") 
     36    head :ok 
     37  end 
    2838end 
    2939 
     
    6878    assert_response :ok 
    6979    assert_page_cached :ok, "get with ok status should have been cached" 
     80  end 
     81 
     82  def test_should_cache_with_custom_path 
     83    get :custom_path 
     84    assert File.exist?("#{FILE_STORE_PATH}/index.html") 
     85  end 
     86 
     87  def test_should_expire_cache_with_custom_path 
     88    get :custom_path 
     89    assert File.exist?("#{FILE_STORE_PATH}/index.html") 
     90 
     91    get :expire_custom_path 
     92    assert !File.exist?("#{FILE_STORE_PATH}/index.html") 
    7093  end 
    7194 
     
    97120end 
    98121 
     122 
    99123class ActionCachingTestController < ActionController::Base 
    100124  caches_action :index