Skip to content

Instantly share code, notes, and snippets.

@abhishek-sisodiya
Last active August 21, 2019 07:50
Show Gist options
  • Save abhishek-sisodiya/f6744855b9070ec64c04b683b565300a to your computer and use it in GitHub Desktop.
Save abhishek-sisodiya/f6744855b9070ec64c04b683b565300a to your computer and use it in GitHub Desktop.
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