aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2014-04-22 22:18:41 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2014-04-22 22:18:41 +1200
commitbd9d93b7731b6d5cc0c7fd4287a36f52d00dc05c (patch)
treee688be8915539defd73e97f3fa03a3d662018f31 /src/org
parent8214596eb5948e6e55de498eaedb67a1a0049481 (diff)
downloadtrackermap-server-bd9d93b7731b6d5cc0c7fd4287a36f52d00dc05c.tar.gz
trackermap-server-bd9d93b7731b6d5cc0c7fd4287a36f52d00dc05c.tar.bz2
trackermap-server-bd9d93b7731b6d5cc0c7fd4287a36f52d00dc05c.zip
Improve device caching
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/model/DatabaseDataManager.java22
1 files changed, 3 insertions, 19 deletions
diff --git a/src/org/traccar/model/DatabaseDataManager.java b/src/org/traccar/model/DatabaseDataManager.java
index ca5cb1372..3799c5461 100644
--- a/src/org/traccar/model/DatabaseDataManager.java
+++ b/src/org/traccar/model/DatabaseDataManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2013 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2014 Anton Tananaev (anton.tananaev@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,11 +21,7 @@ import java.net.URL;
import java.net.URLClassLoader;
import java.sql.*;
import java.util.*;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import javax.xml.namespace.QName;
import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.traccar.helper.AdvancedConnection;
@@ -70,14 +66,6 @@ public class DatabaseDataManager implements DataManager {
}
}
- // Refresh delay
- String refreshDelay = properties.getProperty("database.refreshDelay");
- if (refreshDelay != null) {
- devicesRefreshDelay = Long.valueOf(refreshDelay) * 1000;
- } else {
- devicesRefreshDelay = new Long(300) * 1000; // Magic number
- }
-
// Connect database
String url = properties.getProperty("database.url");
String user = properties.getProperty("database.user");
@@ -126,19 +114,15 @@ public class DatabaseDataManager implements DataManager {
* Devices cache
*/
private Map<String, Device> devices;
- private Calendar devicesLastUpdate;
- private Long devicesRefreshDelay;
@Override
public Device getDeviceByImei(String imei) throws SQLException {
- if ((devices == null) || (Calendar.getInstance().getTimeInMillis() - devicesLastUpdate.getTimeInMillis() > devicesRefreshDelay)) {
- List<Device> list = getDevices();
+ if (devices == null || !devices.containsKey(imei)) {
devices = new HashMap<String, Device>();
- for (Device device: list) {
+ for (Device device: getDevices()) {
devices.put(device.getImei(), device);
}
- devicesLastUpdate = Calendar.getInstance();
}
return devices.get(imei);