Class: GoogleDistanceMatrix::ClientCache

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, cache) ⇒ ClientCache

Returns a new instance of ClientCache.



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

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

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



3
4
5
# File 'lib/google_distance_matrix/client_cache.rb', line 3

def cache
  @cache
end

#clientObject (readonly)

Returns the value of attribute client.



3
4
5
# File 'lib/google_distance_matrix/client_cache.rb', line 3

def client
  @client
end

Class Method Details

.key(url) ⇒ Object



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

def self.key(url)
  url
end

Instance Method Details

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



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

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