Sha256: eedaf9d1343ecc4fb880787bad42fb0d62b5d059c2a988dd04e5ffdaa46ddf3c

Contents?: true

Size: 743 Bytes

Versions: 1

Compression:

Stored size: 743 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.host + url.request_uri + env[:body].to_s # XXX add for POST requests
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pupa-0.1.6 lib/pupa/refinements/faraday_middleware.rb