Sha256: 5cd78b1f42d7e961880b896fec9986b4cf9056d8234fb1cf793d357d2ad76790

Contents?: true

Size: 711 Bytes

Versions: 2

Compression:

Stored size: 711 Bytes

Contents

# Caches all requests, not only GET requests.
class FaradayMiddleware::Caching
  def call(env)
    # Remove if-statement to cache any request, not only GET.
    if env[:parallel_manager]
      # callback mode
      cache_on_complete(env)
    else
      # synchronous mode
      response = cache.fetch(cache_key(env)) { @app.call(env) }
      finalize_response(response, env)
    end
  end

  def cache_key(env)
    url = env[:url].dup
    if url.query && params_to_ignore.any?
      params = parse_query url.query
      params.reject! {|k,| params_to_ignore.include? k }
      url.query = build_query params
    end
    url.normalize!
    url.request_uri + env[:body].to_s # XXX add for POST requests
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pupa-0.0.13 lib/pupa/refinements/faraday_middleware.rb
pupa-0.0.12 lib/pupa/refinements/faraday_middleware.rb