Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Commit

Permalink
render with cache options are passed on to cache.write
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanb committed Jun 19, 2008
1 parent 0912172 commit fedadd2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/render_caching/controller_additions.rb
Expand Up @@ -2,15 +2,15 @@ module RenderCaching
module ControllerAdditions
private

def render_with_cache(key = nil)
def render_with_cache(key = nil, options = nil)
key ||= request.request_uri
body = Rails.cache.read(key)
if body
render :text => body
else
yield if block_given?
render unless performed?
Rails.cache.write(key, response.body)
Rails.cache.write(key, response.body, options)
end
end
end
Expand Down
5 changes: 5 additions & 0 deletions spec/render_caching/controller_additions_spec.rb
Expand Up @@ -74,4 +74,9 @@ def self.cache
Rails.cache.write('some_key', 'page content')
render_with_cache('some_key') { violated('block was executed') }
end

it "should pass options to cache write call" do
Rails.cache.expects(:write).with('some_key', @response.body, :expires_in => 5)
render_with_cache('some_key', :expires_in => 5)
end
end

0 comments on commit fedadd2

Please sign in to comment.