Class: GoogleDistanceMatrix::ClientCache

Inherits:
Object
  • Object
show all
Defined in:
lib/google_distance_matrix/client_cache.rb

Overview

Cached client, which takes care of caching data from Google API

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, cache) ⇒ ClientCache

Returns a new instance of ClientCache.



15
16
17
18
# File 'lib/google_distance_matrix/client_cache.rb', line 15

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

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



6
7
8
# File 'lib/google_distance_matrix/client_cache.rb', line 6

def cache
  @cache
end

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/google_distance_matrix/client_cache.rb', line 6

def client
  @client
end

Class Method Details

.key(url, config) ⇒ Object

Returns a cache key for given URL

Returns:

  • String



11
12
13
# File 'lib/google_distance_matrix/client_cache.rb', line 11

def self.key(url, config)
  config.cache_key_transform.call url
end

Instance Method Details

#get(url, options = {}) ⇒ Object



20
21
22
23
24
# File 'lib/google_distance_matrix/client_cache.rb', line 20

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