lib/renderers/cache.rb in garterbelt-0.0.2 vs lib/renderers/cache.rb in garterbelt-0.0.3
- old
+ new
@@ -1,20 +1,25 @@
module Garterbelt
class Cache < Renderer
include ContentRendering
- attr_accessor :key, :cache_output, :view_output
+ attr_accessor :key, :cache_output, :view_output, :expires_in
def initialize(opts, &block)
super
self.key = opts[:key]
+ self.expires_in = opts[:expires_in]
raise ArgumentError, ":key option required" unless key
self.content = block if block_given?
raise_unless_block_content
self.cache_output = ""
end
+ def cache_options
+ expires_in ? {:expires_in => expires_in} : {}
+ end
+
def head
self.view_output = output
self.output = cache_output
end
@@ -25,11 +30,11 @@
def render_content
if cached = view.cache_store[key]
self.output << cached
else
- super # renders block to the diverted output
- view.cache_store[key] = cache_output # set the cache
+ super # renders block to the diverted output
+ view.cache_store.store(key, cache_output, cache_options) # set the cache
end
end
end
end