Leave a tombstone after the deletion of a cache entry

This captures the scenario of multiple deletion calls in the current session.

Closes #28672

Signed-off-by: Alexander Schwartz <aschwart@redhat.com>
This commit is contained in:
Alexander Schwartz 2024-04-12 12:07:15 +02:00 committed by Alexander Schwartz
parent 6853dca002
commit 004f419fd0

View file

@ -36,6 +36,21 @@ public class InfinispanKeycloakTransaction implements KeycloakTransaction {
private final static Logger log = Logger.getLogger(InfinispanKeycloakTransaction.class); private final static Logger log = Logger.getLogger(InfinispanKeycloakTransaction.class);
/**
* Tombstone to mark an entry as already removed for the current session.
*/
private static final CacheTask TOMBSTONE = new CacheTask() {
@Override
public void execute() {
// noop
}
@Override
public String toString() {
return "Tombstone after removal";
}
};
public enum CacheOperation { public enum CacheOperation {
ADD, ADD_WITH_LIFESPAN, REMOVE, REPLACE, ADD_IF_ABSENT // ADD_IF_ABSENT throws an exception if there is existing value ADD, ADD_WITH_LIFESPAN, REMOVE, REPLACE, ADD_IF_ABSENT // ADD_IF_ABSENT throws an exception if there is existing value
} }
@ -205,7 +220,10 @@ public class InfinispanKeycloakTransaction implements KeycloakTransaction {
CacheTask current = tasks.get(taskKey); CacheTask current = tasks.get(taskKey);
if (current != null) { if (current != null) {
if (current instanceof CacheTaskWithValue && ((CacheTaskWithValue<?>) current).getOperation() == Operation.PUT) { if (current instanceof CacheTaskWithValue && ((CacheTaskWithValue<?>) current).getOperation() == Operation.PUT) {
tasks.remove(taskKey); tasks.put(taskKey, TOMBSTONE);
return;
}
if (current == TOMBSTONE) {
return; return;
} }
} }