Sha256: 39a65a3289fe55388d927cf80df14295e1a8443e842382c005e5ecfbc59c1bbd

Contents?: true

Size: 630 Bytes

Versions: 2

Compression:

Stored size: 630 Bytes

Contents

module MarketoApi
  class Middleware::Caching < FaradayMiddleware::Caching
    def call(env)
      expire(cache_key(env)) unless use_cache?
      super
    end

    def expire(key)
      cache.delete(key) if cache
    end

    # We don't want to cache requests for different clients, so append the
    # oauth token to the cache key.
    def cache_key(env)
      super(env) + hashed_auth_header(env)
    end

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

    def hashed_auth_header(env)
      Digest::SHA1.hexdigest(env[:request_headers][MarketoApi::Middleware::Authorization::AUTH_HEADER])
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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