Sha256: b78cec3bbce9346247badbb5ed29553771013ba8d2f02a38a8967de07a7a4984

Contents?: true

Size: 663 Bytes

Versions: 18

Compression:

Stored size: 663 Bytes

Contents

# frozen_string_literal: true

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

    def expire(key)
      cache&.delete(key)
    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][Restforce::Middleware::Authorization::AUTH_HEADER]
      )
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
frodo-0.12.8 lib/frodo/middleware/caching.rb
frodo-0.12.7 lib/frodo/middleware/caching.rb
frodo-0.12.6 lib/frodo/middleware/caching.rb
frodo-0.12.5 lib/frodo/middleware/caching.rb
frodo-0.12.4 lib/frodo/middleware/caching.rb
frodo-0.12.2 lib/frodo/middleware/caching.rb
frodo-0.12.1 lib/frodo/middleware/caching.rb
frodo-0.12.0 lib/frodo/middleware/caching.rb
frodo-0.11.0 lib/frodo/middleware/caching.rb
frodo-0.10.8 lib/frodo/middleware/caching.rb
frodo-0.10.7 lib/frodo/middleware/caching.rb
frodo-0.10.6 lib/frodo/middleware/caching.rb
frodo-0.10.5 lib/frodo/middleware/caching.rb
frodo-0.10.4 lib/frodo/middleware/caching.rb
frodo-0.10.3 lib/frodo/middleware/caching.rb
frodo-0.10.2 lib/frodo/middleware/caching.rb
frodo-0.10.1 lib/frodo/middleware/caching.rb
frodo-0.10.0 lib/frodo/middleware/caching.rb