aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/api
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
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')
-rw-r--r--src/main/java/org/traccar/api/BaseObjectResource.java8
-rw-r--r--src/main/java/org/traccar/api/resource/PermissionsResource.java9
2 files changed, 17 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);
diff --git a/src/main/java/org/traccar/api/resource/PermissionsResource.java b/src/main/java/org/traccar/api/resource/PermissionsResource.java
index 484c61e66..a4db6754c 100644
--- a/src/main/java/org/traccar/api/resource/PermissionsResource.java
+++ b/src/main/java/org/traccar/api/resource/PermissionsResource.java
@@ -20,8 +20,10 @@ import org.traccar.Context;
import org.traccar.api.BaseResource;
import org.traccar.helper.LogAction;
import org.traccar.model.Permission;
+import org.traccar.session.cache.CacheManager;
import org.traccar.storage.StorageException;
+import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.POST;
@@ -40,6 +42,9 @@ import java.util.Set;
@Consumes(MediaType.APPLICATION_JSON)
public class PermissionsResource extends BaseResource {
+ @Inject
+ private CacheManager cacheManager;
+
private void checkPermission(Permission permission, boolean link) throws StorageException {
if (permissionsService.notAdmin(getUserId())) {
permissionsService.checkPermission(permission.getOwnerClass(), getUserId(), permission.getOwnerId());
@@ -67,6 +72,8 @@ public class PermissionsResource extends BaseResource {
checkPermission(permission, true);
Context.getDataManager().linkObject(permission.getOwnerClass(), permission.getOwnerId(),
permission.getPropertyClass(), permission.getPropertyId(), true);
+ cacheManager.invalidate(permission.getOwnerClass(), permission.getOwnerId(),
+ permission.getPropertyClass(), permission.getPropertyId());
LogAction.link(getUserId(), permission.getOwnerClass(), permission.getOwnerId(),
permission.getPropertyClass(), permission.getPropertyId());
}
@@ -91,6 +98,8 @@ public class PermissionsResource extends BaseResource {
checkPermission(permission, false);
Context.getDataManager().linkObject(permission.getOwnerClass(), permission.getOwnerId(),
permission.getPropertyClass(), permission.getPropertyId(), false);
+ cacheManager.invalidate(permission.getOwnerClass(), permission.getOwnerId(),
+ permission.getPropertyClass(), permission.getPropertyId());
LogAction.unlink(getUserId(), permission.getOwnerClass(), permission.getOwnerId(),
permission.getPropertyClass(), permission.getPropertyId());
}