fix: cache warnings
This commit is contained in:
parent
61a459ce78
commit
83c12599c7
@ -12,9 +12,9 @@ import org.json.JSONObject;
|
|||||||
|
|
||||||
public class WeatherDataCache {
|
public class WeatherDataCache {
|
||||||
private static class CacheValue {
|
private static class CacheValue {
|
||||||
private WeatherData value;
|
private final WeatherData value;
|
||||||
private int day;
|
private final int day;
|
||||||
private Instant timestamp;
|
private final Instant timestamp;
|
||||||
|
|
||||||
CacheValue(WeatherData value, int day, Instant timestamp) {
|
CacheValue(WeatherData value, int day, Instant timestamp) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
@ -61,7 +61,7 @@ public class WeatherDataCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private HashMap<String, CacheValue> cache = new HashMap<>();
|
private HashMap<String, CacheValue> cache = new HashMap<>();
|
||||||
private long cacheTTL = 3600; // Cache data Time To Live in sec
|
private static final long cacheTTL = 3600; // Cache data Time To Live in sec
|
||||||
|
|
||||||
private String makeKey(String cityName, int day) {
|
private String makeKey(String cityName, int day) {
|
||||||
return String.format(Locale.ENGLISH, "%s%d", cityName, day);
|
return String.format(Locale.ENGLISH, "%s%d", cityName, day);
|
||||||
@ -87,7 +87,7 @@ public class WeatherDataCache {
|
|||||||
|
|
||||||
long dt = Instant.now().getEpochSecond() - cacheValue.getTimestamp().getEpochSecond();
|
long dt = Instant.now().getEpochSecond() - cacheValue.getTimestamp().getEpochSecond();
|
||||||
|
|
||||||
return dt > this.cacheTTL; // if older than TTL, needs update
|
return dt > cacheTTL; // if older than TTL, needs update
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user