diff --git a/lib/geocoder/lookups/base.rb b/lib/geocoder/lookups/base.rb index d24b912a7e50bcd9ba9280f698237f049febb8e3..6c80e5ec8f44597ad8bde7e9c096ddffb8a26993 100644 --- a/lib/geocoder/lookups/base.rb +++ b/lib/geocoder/lookups/base.rb @@ -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) @@ -150,6 +156,7 @@ module Geocoder if cache and (200..399).include?(response.code.to_i) cache[url] = body end + @cache_hit = false end body end diff --git a/lib/geocoder/results/base.rb b/lib/geocoder/results/base.rb index 645e3c2a29e1400f4e25b567aaafed4eba3040de..8a42413f229dff258629fb64785518eee212f3e2 100644 --- a/lib/geocoder/results/base.rb +++ b/lib/geocoder/results/base.rb @@ -1,13 +1,14 @@ 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 ##