aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/session
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-08 08:14:20 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-08 08:14:20 -0700
commit65d3654dcca878cfd839e40c0dd020da199be09e (patch)
tree8313b00d39f9b0203fb4e873cab4737cca985f07 /src/main/java/org/traccar/session
parentcd229daa23cfc43ad5056c45c4aaecefdbbf826c (diff)
downloadtrackermap-server-65d3654dcca878cfd839e40c0dd020da199be09e.tar.gz
trackermap-server-65d3654dcca878cfd839e40c0dd020da199be09e.tar.bz2
trackermap-server-65d3654dcca878cfd839e40c0dd020da199be09e.zip
More cache improvements
Diffstat (limited to 'src/main/java/org/traccar/session')
-rw-r--r--src/main/java/org/traccar/session/cache/CacheManager.java35
1 files changed, 21 insertions, 14 deletions
diff --git a/src/main/java/org/traccar/session/cache/CacheManager.java b/src/main/java/org/traccar/session/cache/CacheManager.java
index 8e1737441..a934431be 100644
--- a/src/main/java/org/traccar/session/cache/CacheManager.java
+++ b/src/main/java/org/traccar/session/cache/CacheManager.java
@@ -136,36 +136,43 @@ public class CacheManager {
}
}
- public void updateOrInvalidate(Class<? extends BaseModel> clazz, long id) throws StorageException {
- boolean invalidate = false;
- var before = getObject(clazz, id);
- var after = storage.getObject(clazz, new Request(
+ public <T extends BaseModel> void updateOrInvalidate(Class<T> clazz, long id) throws StorageException {
+ var object = storage.getObject(clazz, new Request(
new Columns.All(), new Condition.Equals("id", "id", id)));
+ if (object != null) {
+ updateOrInvalidate(object);
+ } else {
+ invalidate(clazz, id);
+ }
+ }
+
+ public <T extends BaseModel> void updateOrInvalidate(T object) throws StorageException {
+ boolean invalidate = false;
+ var before = getObject(object.getClass(), object.getId());
if (before == null) {
return;
- } else if (after == null) {
- invalidate = true;
- } else if (clazz.isInstance(GroupedModel.class)) {
- if (((GroupedModel) before).getGroupId() != ((GroupedModel) after).getGroupId()) {
+ } else if (object instanceof GroupedModel) {
+ if (((GroupedModel) before).getGroupId() != ((GroupedModel) object).getGroupId()) {
invalidate = true;
}
}
if (invalidate) {
- invalidate(new CacheKey(clazz, id));
+ invalidate(object.getClass(), object.getId());
} else {
+ // TODO if device, also need to update geofences
try {
lock.writeLock().lock();
- var cacheValue = deviceCache.get(new CacheKey(clazz, id));
- if (cacheValue != null) {
- cacheValue.setValue(after);
- }
- // TODO if device, also need to update geofences
+ deviceCache.get(new CacheKey(object.getClass(), object.getId())).setValue(object);
} finally {
lock.writeLock().unlock();
}
}
}
+ public <T extends BaseModel> void invalidate(Class<T> clazz, long id) throws StorageException {
+ invalidate(new CacheKey(clazz, id));
+ }
+
public void invalidate(
Class<? extends BaseModel> clazz1, long id1,
Class<? extends BaseModel> clazz2, long id2) throws StorageException {