Module: ErectorCache::AbstractWidget::InstanceMethods

Defined in:
lib/erector_cache/abstract_widget.rb

Instance Method Summary collapse

Instance Method Details

#_emit_via_with_caching(parent, options = {}) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/erector_cache/abstract_widget.rb', line 66

def _emit_via_with_caching(parent, options={})
  if self.class.key_components.blank?
    _emit_via_without_caching(parent, options)
  else
    options = {:expire_in => @expire_in || 1.hour, :raw => true}
    unless self.class.interpolations.blank?
      options[:interpolate] = self.class.interpolations.inject({}) do |collection, interpolation| 
        collection[interpolation.first] = self.instance_variable_get("@#{interpolation.last}")
        collection
      end
    end
    
    cached_fragment = LAWNCHAIR.cache(cache_key, options) do
      parent.capture { _emit_via_without_caching(parent, options) }
    end
    parent.output << cached_fragment.html_safe  
  end
end

#cache_keyObject



57
58
59
60
61
62
63
64
# File 'lib/erector_cache/abstract_widget.rb', line 57

def cache_key
  key_data = {}
  self.class.key_components.each do |part|
    part = part.keys.first if part.is_a?(Hash)
    key_data[part] = self.instance_variable_get("@#{part}")
  end
  return self.class.cache_key(key_data)
end