diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2014-10-22 10:09:32 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2014-10-22 10:09:32 +1300 |
commit | 5490a0351abc9d6e741baf129300beb2d50051fd (patch) | |
tree | a513f8f253bcd47e49bdf08378980b3d8fc09446 /src/org/traccar/database | |
parent | 91395e9ac0dd5de366b87bb5d082990b15a946e9 (diff) | |
download | trackermap-server-5490a0351abc9d6e741baf129300beb2d50051fd.tar.gz trackermap-server-5490a0351abc9d6e741baf129300beb2d50051fd.tar.bz2 trackermap-server-5490a0351abc9d6e741baf129300beb2d50051fd.zip |
Put back cache timeout (fix #933)
Diffstat (limited to 'src/org/traccar/database')
-rw-r--r-- | src/org/traccar/database/DataManager.java | 15 |
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); |