Sha256: b54bf99e074a4b9e38ca47448856b5f012108aee8d778b9f7ecd5cbe7b9e052f

Contents?: true

Size: 708 Bytes

Versions: 4

Compression:

Stored size: 708 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 # Add for POST requests.
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pupa-0.0.11 lib/pupa/refinements/faraday_middleware.rb
pupa-0.0.10 lib/pupa/refinements/faraday_middleware.rb
pupa-0.0.9 lib/pupa/refinements/faraday_middleware.rb
pupa-0.0.8 lib/pupa/refinements/faraday_middleware.rb