Last active
August 21, 2019 07:50
-
-
Save abhishek-sisodiya/f6744855b9070ec64c04b683b565300a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Map<String, Object> cachedData = cacheManager.get(lat + longi, "darksky", Map.class); | |
if (cachedData != null) { | |
return cachedData; | |
} else { | |
Map<String, Object> json = new HashMap<String, Object>(); | |
RestTemplate restTemplate = new RestTemplate(); | |
String url = String.format("https://api.darksky.net/forecast/%s/%s,%s", darkskyKey, lat, longi); | |
try { | |
ResponseEntity<Object> response = restTemplate.getForEntity(url, Object.class); | |
json.put("darksky", response.getBody()); | |
cacheManager.put(lat + longi, "darksky", json); | |
cacheManager.expire(lat + longi); | |
} catch (Exception e) { | |
if (DSKeyCount == 2) { | |
darkskyKey = System.getenv("DARKSKY_API_KEY_2"); | |
darksky(lat, longi); | |
} else { | |
json.put("darksky", e.toString()); | |
} | |
} | |
return json; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment