Class: Garterbelt::Cache
- Includes:
- ContentRendering
- Defined in:
- lib/renderers/cache.rb
Instance Attribute Summary collapse
-
#cache_output ⇒ Object
Returns the value of attribute cache_output.
-
#expires_in ⇒ Object
Returns the value of attribute expires_in.
-
#key ⇒ Object
Returns the value of attribute key.
-
#view_output ⇒ Object
Returns the value of attribute view_output.
Attributes inherited from Renderer
Instance Method Summary collapse
- #cache_options ⇒ Object
- #foot ⇒ Object
- #head ⇒ Object
-
#initialize(opts, &block) ⇒ Cache
constructor
A new instance of Cache.
- #render_content ⇒ Object
Methods included from ContentRendering
Methods inherited from Renderer
#indent, #level, #line_end, #output, #output=, #render
Constructor Details
#initialize(opts, &block) ⇒ Cache
Returns a new instance of Cache.
7 8 9 10 11 12 13 14 15 |
# File 'lib/renderers/cache.rb', line 7 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 |
Instance Attribute Details
#cache_output ⇒ Object
Returns the value of attribute cache_output.
5 6 7 |
# File 'lib/renderers/cache.rb', line 5 def cache_output @cache_output end |
#expires_in ⇒ Object
Returns the value of attribute expires_in.
5 6 7 |
# File 'lib/renderers/cache.rb', line 5 def expires_in @expires_in end |
#key ⇒ Object
Returns the value of attribute key.
5 6 7 |
# File 'lib/renderers/cache.rb', line 5 def key @key end |
#view_output ⇒ Object
Returns the value of attribute view_output.
5 6 7 |
# File 'lib/renderers/cache.rb', line 5 def view_output @view_output end |
Instance Method Details
#cache_options ⇒ Object
17 18 19 |
# File 'lib/renderers/cache.rb', line 17 def expires_in ? {:expires_in => expires_in} : {} end |
#foot ⇒ Object
26 27 28 29 |
# File 'lib/renderers/cache.rb', line 26 def foot view_output << cache_output self.output = view_output end |
#head ⇒ Object
21 22 23 24 |
# File 'lib/renderers/cache.rb', line 21 def head self.view_output = output self.output = cache_output end |
#render_content ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/renderers/cache.rb', line 31 def render_content if cached = view.cache_store[key] self.output << cached else super # renders block to the diverted output view.cache_store.store(key, cache_output, ) # set the cache end end |