Changeset 4656
- Timestamp:
- 08/03/06 23:59:38 (2 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/caching.rb (modified) (4 diffs)
- trunk/actionpack/test/controller/action_caching_test.rb (added)
- trunk/actionpack/test/controller/base_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r4644 r4656 1 1 *SVN* 2 3 * Make action caching aware of different formats for the same action so that, e.g. foo.xml is cached separately from foo.html. Implicitly set content type when reading in cached content with mime revealing extensions so the entire onous isn't on the webserver. [Marcel Molina Jr.] 2 4 3 5 * Restrict Request Method hacking with ?_method to POST requests. [Rick Olson] trunk/actionpack/lib/action_controller/caching.rb
r4310 r4656 156 156 # "david.somewhere.com/lists/show/1". This allows the cacher to differentiate between "david.somewhere.com/lists/" and 157 157 # "jamis.somewhere.com/lists/" -- which is a helpful way of assisting the subdomain-as-account-key pattern. 158 # 159 # Different representations of the same resource, e.g. <tt>http://david.somewhere.com/lists</tt> and <tt>http://david.somewhere.com/lists.xml</tt> 160 # are treated like separate requests and are so are cached separately. Keep in mine when expiring an action cache that <tt>:action => 'lists'</tt> is not the same 161 # as <tt>:action => 'list', :format => :xml</tt>. 158 162 module Actions 159 163 def self.included(base) #:nodoc: … … 173 177 if options[:action].is_a?(Array) 174 178 options[:action].dup.each do |action| 175 expire_fragment( url_for(options.merge({ :action => action })).split("://").last)179 expire_fragment(ActionCachePath.path_for(self, options.merge({ :action => action }))) 176 180 end 177 181 else 178 expire_fragment( url_for(options).split("://").last)179 end 180 end 181 182 class ActionCacheFilter #:nodoc: 183 def initialize(*actions )182 expire_fragment(ActionCachePath.path_for(self, options)) 183 end 184 end 185 186 class ActionCacheFilter #:nodoc: 187 def initialize(*actions, &block) 184 188 @actions = actions 185 189 end … … 187 191 def before(controller) 188 192 return unless @actions.include?(controller.action_name.intern) 189 if cache = controller.read_fragment(controller.url_for.split("://").last) 193 action_cache_path = ActionCachePath.new(controller) 194 if cache = controller.read_fragment(action_cache_path.path) 190 195 controller.rendered_action_cache = true 196 set_content_type!(action_cache_path) 191 197 controller.send(:render_text, cache) 192 198 false … … 196 202 def after(controller) 197 203 return if !@actions.include?(controller.action_name.intern) || controller.rendered_action_cache 198 controller.write_fragment(controller.url_for.split("://").last, controller.response.body) 199 end 204 controller.write_fragment(ActionCachePath.path_for(controller), controller.response.body) 205 end 206 207 private 208 209 def set_content_type!(action_cache_path) 210 if extention = action_cache_path.extension 211 content_type = Mime::EXTENSION_LOOKUP[extention] 212 action_cache_path.controller.headers['Content-Type'] = content_type.to_s 213 end 214 end 215 216 end 217 218 class ActionCachePath 219 attr_reader :controller, :options 220 221 class << self 222 def path_for(*args, &block) 223 new(*args).path 224 end 225 end 226 227 def initialize(controller, options = {}) 228 @controller = controller 229 @options = options 230 end 231 232 def path 233 return @path if @path 234 @path = controller.url_for(options).split('://').last 235 normalize! 236 add_extension! 237 URI.unescape(@path) 238 end 239 240 def extension 241 @extension ||= extract_extension(controller.request.path) 242 end 243 244 private 245 def normalize! 246 @path << 'index' if @path.last == '/' 247 end 248 249 def add_extension! 250 @path << ".#{extension}" if extension 251 end 252 253 def extract_extension(file_path) 254 # Don't want just what comes after the last '.' to accomodate multi part extensions 255 # such as tar.gz. 256 file_path[/^[^.]+\.(.+)$/, 1] 257 end 200 258 end 201 259 end trunk/actionpack/test/controller/base_test.rb
r3668 r4656 24 24 end 25 25 class EmptyController < ActionController::Base 26 include ActionController::Caching27 26 end 28 27 class NonEmptyController < ActionController::Base