Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.UnaryOperator;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -60,6 +61,7 @@ public class TemporaryResourceCache<T extends HasMetadata> {
private String latestResourceVersion;

private final Map<ResourceID, EventFilterDetails> activeUpdates = new HashMap<>();
private final UnaryOperator<T> transformationFunction;

public enum EventHandling {
DEFER,
Expand All @@ -68,7 +70,13 @@ public enum EventHandling {
}

public TemporaryResourceCache(boolean comparableResourceVersions) {
this(comparableResourceVersions, t -> t);
}

public TemporaryResourceCache(
boolean comparableResourceVersions, UnaryOperator<T> transformationFunction) {
this.comparableResourceVersions = comparableResourceVersions;
this.transformationFunction = transformationFunction;
}

public synchronized void startEventFilteringModify(ResourceID resourceID) {
Expand Down Expand Up @@ -204,7 +212,7 @@ public synchronized void putResource(T newResource) {
"Temporarily moving ahead to target version {} for resource id: {}",
newResource.getMetadata().getResourceVersion(),
resourceId);
cache.put(resourceId, newResource);
cache.put(resourceId, transformationFunction.apply(newResource));
}
}

Expand Down
Loading