aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/api/BaseObjectResource.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-08 07:52:59 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-08 07:52:59 -0700
commitcd229daa23cfc43ad5056c45c4aaecefdbbf826c (patch)
tree4dd8932cda394d20e59143e5e44714695f21c549 /src/main/java/org/traccar/api/BaseObjectResource.java
parent5890e03199142f041dc19160329a740b4d01450d (diff)
downloadtrackermap-server-cd229daa23cfc43ad5056c45c4aaecefdbbf826c.tar.gz
trackermap-server-cd229daa23cfc43ad5056c45c4aaecefdbbf826c.tar.bz2
trackermap-server-cd229daa23cfc43ad5056c45c4aaecefdbbf826c.zip
Improve cache invalidation
Diffstat (limited to 'src/main/java/org/traccar/api/BaseObjectResource.java')
-rw-r--r--src/main/java/org/traccar/api/BaseObjectResource.java8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/main/java/org/traccar/api/BaseObjectResource.java b/src/main/java/org/traccar/api/BaseObjectResource.java
index d6401dc42..c033fbb62 100644
--- a/src/main/java/org/traccar/api/BaseObjectResource.java
+++ b/src/main/java/org/traccar/api/BaseObjectResource.java
@@ -27,11 +27,13 @@ import org.traccar.model.Device;
import org.traccar.model.Group;
import org.traccar.model.Permission;
import org.traccar.model.User;
+import org.traccar.session.cache.CacheManager;
import org.traccar.storage.StorageException;
import org.traccar.storage.query.Columns;
import org.traccar.storage.query.Condition;
import org.traccar.storage.query.Request;
+import javax.inject.Inject;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
@@ -42,6 +44,9 @@ import javax.ws.rs.core.Response;
public abstract class BaseObjectResource<T extends BaseModel> extends BaseResource {
+ @Inject
+ private CacheManager cacheManager;
+
protected final Class<T> baseClass;
public BaseObjectResource(Class<T> baseClass) {
@@ -75,6 +80,7 @@ public abstract class BaseObjectResource<T extends BaseModel> extends BaseResour
LogAction.create(getUserId(), entity);
storage.addPermission(new Permission(User.class, getUserId(), baseClass, entity.getId()));
+ cacheManager.invalidate(User.class, getUserId(), baseClass, entity.getId());
LogAction.link(getUserId(), User.class, getUserId(), baseClass, entity.getId());
if (manager instanceof SimpleObjectManager) {
@@ -100,6 +106,7 @@ public abstract class BaseObjectResource<T extends BaseModel> extends BaseResour
new Columns.Exclude("id"),
new Condition.Equals("id", "id")));
}
+ cacheManager.updateOrInvalidate(baseClass, entity.getId());
LogAction.edit(getUserId(), entity);
@@ -128,6 +135,7 @@ public abstract class BaseObjectResource<T extends BaseModel> extends BaseResour
} else {
storage.removeObject(baseClass, new Request(new Condition.Equals("id", "id", id)));
}
+ cacheManager.updateOrInvalidate(baseClass, id);
LogAction.remove(getUserId(), baseClass, id);