Class: GoogleDistanceMatrix::ClientCache
- Inherits:
-
Object
- Object
- GoogleDistanceMatrix::ClientCache
- 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
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Class Method Summary collapse
-
.key(url, config) ⇒ Object
Returns a cache key for given URL.
Instance Method Summary collapse
- #get(url, options = {}) ⇒ Object
-
#initialize(client, cache) ⇒ ClientCache
constructor
A new instance of ClientCache.
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
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
6 7 8 |
# File 'lib/google_distance_matrix/client_cache.rb', line 6 def cache @cache end |
#client ⇒ Object (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
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, = {}) cache.fetch self.class.key(url, .fetch(:configuration)) do client.get url, ** end end |