Sha256: bf83b9c7d640dcda0d001c761822fae79ed7ee0784916b148d33de1f85f06cf8

Contents?: true

Size: 731 Bytes

Versions: 1

Compression:

Stored size: 731 Bytes

Contents

module MarketoApi
  class Middleware::Caching < Faraday::HttpCache
    def call(env)
      unless use_cache?
        expire(@strategy.cache_key_for(
                 env[:url],
                 env[:request_headers][MarketoApi::Middleware::Authorization::AUTH_HEADER]
               ))
      end
      super
    end

    def expire(key)
      @strategy.delete(key)
    end

    def delete(request, response)
      headers = %w[Location Content-Location]
      headers.each do |header|
        url = response.headers[header]
        @strategy.delete(request, url) if url
      end

      @strategy.delete(request, request.url)
      trace :delete
    end

    def use_cache?
      @options.fetch(:use_cache, true)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
marketo_api-0.3.0.pre.alpha lib/marketo_api/middleware/caching.rb