aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2014-10-22 10:09:32 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2014-10-22 10:09:32 +1300
commit5490a0351abc9d6e741baf129300beb2d50051fd (patch)
treea513f8f253bcd47e49bdf08378980b3d8fc09446
parent91395e9ac0dd5de366b87bb5d082990b15a946e9 (diff)
downloadtrackermap-server-5490a0351abc9d6e741baf129300beb2d50051fd.tar.gz
trackermap-server-5490a0351abc9d6e741baf129300beb2d50051fd.tar.bz2
trackermap-server-5490a0351abc9d6e741baf129300beb2d50051fd.zip
Put back cache timeout (fix #933)
-rw-r--r--src/org/traccar/database/DataManager.java15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index bb44c6389..fc83e53a3 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -40,6 +40,14 @@ public class DataManager {
public DataManager(Properties properties) throws Exception {
if (properties != null) {
initDatabase(properties);
+
+ // Refresh delay
+ String refreshDelay = properties.getProperty("database.refreshDelay");
+ if (refreshDelay != null) {
+ devicesRefreshDelay = Long.valueOf(refreshDelay) * 1000;
+ } else {
+ devicesRefreshDelay = DEFAULT_REFRESH_DELAY * 1000;
+ }
}
}
@@ -127,14 +135,19 @@ public class DataManager {
* Devices cache
*/
private Map<String, Device> devices;
+ private Calendar devicesLastUpdate;
+ private long devicesRefreshDelay;
+ private static final long DEFAULT_REFRESH_DELAY = 300;
public Device getDeviceByImei(String imei) throws SQLException {
- if (devices == null || !devices.containsKey(imei)) {
+ if (devices == null || !devices.containsKey(imei) ||
+ (Calendar.getInstance().getTimeInMillis() - devicesLastUpdate.getTimeInMillis() > devicesRefreshDelay)) {
devices = new HashMap<String, Device>();
for (Device device : getDevices()) {
devices.put(device.getImei(), device);
}
+ devicesLastUpdate = Calendar.getInstance();
}
return devices.get(imei);