Skip to content
Snippets Groups Projects
Commit 76b79440 authored by Sam Giffney's avatar Sam Giffney
Browse files

add cache_hit attribute to Geocoder Result to identify whether cache was used

parent 4e924703
No related branches found
No related tags found
No related merge requests found
...@@ -33,7 +33,11 @@ module Geocoder ...@@ -33,7 +33,11 @@ module Geocoder
else else
reverse = false reverse = false
end end
results(query, reverse).map{ |r| result_class.new(r) } results(query, reverse).map{ |r|
result = result_class.new(r)
result.cache_hit = @cache_hit if cache
result
}
end end
## ##
...@@ -142,7 +146,9 @@ module Geocoder ...@@ -142,7 +146,9 @@ module Geocoder
timeout(Geocoder::Configuration.timeout) do timeout(Geocoder::Configuration.timeout) do
url = query_url(query, reverse) url = query_url(query, reverse)
uri = URI.parse(url) uri = URI.parse(url)
unless cache and body = cache[url] if cache and body = cache[url]
@cache_hit = true
else
client = http_client.new(uri.host, uri.port) client = http_client.new(uri.host, uri.port)
client.use_ssl = true if Geocoder::Configuration.use_https client.use_ssl = true if Geocoder::Configuration.use_https
response = client.get(uri.request_uri, Geocoder::Configuration.http_headers) response = client.get(uri.request_uri, Geocoder::Configuration.http_headers)
......
module Geocoder module Geocoder
module Result module Result
class Base class Base
attr_accessor :data attr_accessor :data, :cache_hit
## ##
# Takes a hash of result data from a parsed Google result document. # Takes a hash of result data from a parsed Google result document.
# #
def initialize(data) def initialize(data)
@data = data @data = data
@cache_hit = nil
end end
## ##
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment