diff options
author | Anton Tananaev <anton@traccar.org> | 2022-06-02 17:41:10 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-06-02 17:41:10 -0700 |
commit | 026dc29deee601d3351274a888a73b434c1addfa (patch) | |
tree | 35d4afde48f9b0036ca523329fe8f6ef472d7864 /src/main/java | |
parent | 43942f459f456b05c62ea7549123e28fd7560d56 (diff) | |
download | trackermap-server-026dc29deee601d3351274a888a73b434c1addfa.tar.gz trackermap-server-026dc29deee601d3351274a888a73b434c1addfa.tar.bz2 trackermap-server-026dc29deee601d3351274a888a73b434c1addfa.zip |
Add position cache
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/org/traccar/session/cache/CacheManager.java | 20 |
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)); |