aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/session/cache
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/session/cache')
-rw-r--r--src/main/java/org/traccar/session/cache/CacheManager.java20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/main/java/org/traccar/session/cache/CacheManager.java b/src/main/java/org/traccar/session/cache/CacheManager.java
index f6f04cc36..273c54c9a 100644
--- a/src/main/java/org/traccar/session/cache/CacheManager.java
+++ b/src/main/java/org/traccar/session/cache/CacheManager.java
@@ -24,6 +24,7 @@ import org.traccar.model.Geofence;
import org.traccar.model.Maintenance;
import org.traccar.model.Notification;
import org.traccar.model.Order;
+import org.traccar.model.Position;
import org.traccar.model.User;
import org.traccar.storage.Storage;
import org.traccar.storage.StorageException;
@@ -59,6 +60,7 @@ public class CacheManager {
private final Map<CacheKey, CacheValue> deviceCache = new HashMap<>();
private final Map<Long, Map<Class<? extends BaseModel>, List<Long>>> deviceLinks = new HashMap<>();
+ private final Map<Long, Position> devicePositions = new HashMap<>();
private final Map<Long, List<User>> notificationUsers = new HashMap<>();
@Inject
@@ -87,6 +89,15 @@ public class CacheManager {
}
}
+ public Position getPosition(long deviceId) {
+ try {
+ lock.readLock().lock();
+ return devicePositions.get(deviceId);
+ } finally {
+ lock.readLock().unlock();
+ }
+ }
+
public List<User> getNotificationUsers(long notificationId) {
try {
lock.readLock().lock();
@@ -118,6 +129,15 @@ public class CacheManager {
}
}
+ public void updatePosition(Position position) {
+ try {
+ lock.writeLock().lock();
+ devicePositions.put(position.getDeviceId(), position);
+ } finally {
+ lock.writeLock().unlock();
+ }
+ }
+
public void invalidate(
Class<? extends BaseModel> clazz, long id) throws StorageException {
invalidate(new CacheKey(clazz, id));