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
else
reverse = false
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
##
......@@ -142,7 +146,9 @@ module Geocoder
timeout(Geocoder::Configuration.timeout) do
url = query_url(query, reverse)
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.use_ssl = true if Geocoder::Configuration.use_https
response = client.get(uri.request_uri, Geocoder::Configuration.http_headers)
......
module Geocoder
module Result
class Base
attr_accessor :data
attr_accessor :data, :cache_hit
##
# Takes a hash of result data from a parsed Google result document.
#
def initialize(data)
@data = data
@cache_hit = nil
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