Sha256: a34431ddb644969e76742a5d683c37eaf040ad7fc7c911e9249ee6300b1485e5

Contents?: true

Size: 578 Bytes

Versions: 5

Compression:

Stored size: 578 Bytes

Contents

# frozen_string_literal: true

module GoogleDistanceMatrix
  # Cached client, which takes care of caching data from Google API
  class ClientCache
    attr_reader :client, :cache

    # Returns a cache key for given URL
    #
    # @return String
    def self.key(url, config)
      config.cache_key_transform.call url
    end

    def initialize(client, cache)
      @client = client
      @cache = cache
    end

    def get(url, options = {})
      cache.fetch self.class.key(url, options.fetch(:configuration)) do
        client.get url, options
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
google_distance_matrix-0.6.3 lib/google_distance_matrix/client_cache.rb
google_distance_matrix-0.6.2 lib/google_distance_matrix/client_cache.rb
google_distance_matrix-0.6.1 lib/google_distance_matrix/client_cache.rb
google_distance_matrix-0.6.0 lib/google_distance_matrix/client_cache.rb
google_distance_matrix-0.5.0 lib/google_distance_matrix/client_cache.rb