Sha256: 37cfe2ab91acfd3b5c5792881275d9e7f580e5f2a23c3eb439672523a95061fc

Contents?: true

Size: 764 Bytes

Versions: 5

Compression:

Stored size: 764 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 = params.any? ? build_query(params) : nil
    end
    url.normalize!
    url.scheme + '://' + url.host + url.request_uri + env[:body].to_s # XXX add for POST requests
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pupa-0.1.11 lib/pupa/refinements/faraday_middleware.rb
pupa-0.1.10 lib/pupa/refinements/faraday_middleware.rb
pupa-0.1.9 lib/pupa/refinements/faraday_middleware.rb
pupa-0.1.8 lib/pupa/refinements/faraday_middleware.rb
pupa-0.1.7 lib/pupa/refinements/faraday_middleware.rb