--- fragment_cache.rb 2007-06-10 14:19:58.000000000 -0500 +++ fragment_cache_edit.rb 2007-06-10 14:19:59.000000000 -0500 @@ -32,10 +32,22 @@ module ActsAsCached def initialize(*actions, &block) @actions = actions.inject({}) do |hsh, action| returning(hsh) do - action.is_a?(Hash) ? hsh.update(action) : hsh[action] = { :ttl => nil } + action.is_a?(Hash) ? hsh.update(action) : hsh[action] = { :ttl => nil, :content_type => nil } end end end + + # override to set the content type + def before(controller) + return unless @actions.include?(controller.action_name.intern) + action_cache_path = ActionController::Caching::Actions::ActionCachePath.new(controller) + if cache = controller.read_fragment(action_cache_path.path) + controller.rendered_action_cache = true + set_content_type!(action_cache_path) if controller.rendered_action_cache + controller.send(:render_text, cache) + false + end + end # override to pass along the ttl hash def after(controller) @@ -47,6 +59,15 @@ module ActsAsCached def action_ttl(controller) @actions[controller.action_name.intern] end + + def set_content_type!(action_cache_path) + if content_type = @actions[action_cache_path.controller.action_name.intern][:content_type] + action_cache_path.controller.response.content_type = content_type.to_s + elsif extention = action_cache_path.extension + content_type = Mime::EXTENSION_LOOKUP[extention] + action_cache_path.controller.response.content_type = content_type.to_s + end + end end end @@ -63,4 +84,4 @@ module ActsAsCached def write(*args) "" end end end -end +end \ No newline at end of file