Skip to content

Commit

Permalink
Only cache response if successful.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexreisner committed Dec 15, 2011
1 parent 6e63149 commit 0e157f6
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/geocoder/lookups/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,16 @@ def fetch_raw_data(query, reverse = false)
timeout(Geocoder::Configuration.timeout) do
url = query_url(query, reverse)
uri = URI.parse(url)
unless cache and response = cache[url]
unless cache and body = cache[url]
client = http_client.new(uri.host, uri.port)
client.use_ssl = true if Geocoder::Configuration.use_https
response = client.get(uri.request_uri).body
if cache
cache[url] = response
response = client.get(uri.request_uri)
body = response.body
if cache and (200..399).include?(response.code.to_i)
cache[url] = body
end
end
response
body
end
end

Expand Down

0 comments on commit 0e157f6

Please sign in to comment.