Module: PhantomRenderer
- Defined in:
- lib/phantom_renderer.rb,
lib/phantom_renderer/version.rb
Defined Under Namespace
Classes: Configuration, RenderError, TimeoutError
Constant Summary collapse
- VERSION =
"0.0.1"
Instance Method Summary collapse
Instance Method Details
#render_via_phantom(opts = {}) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/phantom_renderer.rb', line 3 def render_via_phantom(opts = {}) cached = opts[:cache_key] && Rails.cache.read(opts[:cache_key]) if cached ActiveSupport::Notifications.instrument('phantom_renderer.cache.responses.count') render text: cached elsif !requested_by_phantom? uri = get_phantom_uri req = assemble_phantom_request(uri) res = get_response_from_phantom(uri, req) if res ActiveSupport::Notifications.instrument('phantom_renderer.renders.count') Rails.cache.write(opts[:cache_key], res, expires_in: opts[:expires_in]) if opts[:cache_key] render text: res end end end |