Better cache control

This commit is contained in:
Grahame Grieve 2023-08-25 18:43:36 +02:00
parent 0b18b3a3b3
commit 84edac9abe
2 changed files with 37 additions and 10 deletions

View File

@ -1500,26 +1500,39 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
for (CanonicalType c : inc.getValueSet()) {
ValueSet vs = fetchResource(ValueSet.class, c.getValue(), src);
if (vs != null && !hasCanonicalResource(pin, "tx-resource", vs.getVUrl())) {
pin.addParameter().setName("tx-resource").setResource(vs);
if (tcc.isTxCaching() && tcc.getCacheId() == null || !tcc.getCached().contains(vs.getVUrl())) {
tcc.getCached().add(vs.getVUrl());
cache = true;
}
cache = checkAddToParams(pin, vs) || cache;
addDependentResources(pin, vs);
}
}
CodeSystem cs = fetchResource(CodeSystem.class, inc.getSystem(), src);
if (cs != null && !hasCanonicalResource(pin, "tx-resource", cs.getVUrl()) && (cs.getContent() == CodeSystemContentMode.COMPLETE || cs.getContent() == CodeSystemContentMode.FRAGMENT)) {
pin.addParameter().setName("tx-resource").setResource(cs);
if (tcc.isTxCaching() && tcc.getCacheId() == null || !tcc.getCached().contains(cs.getVUrl())) {
tcc.getCached().add(cs.getVUrl());
cache = true;
}
cache = checkAddToParams(pin, cs) || cache;
// todo: supplements
}
return cache;
}
private boolean checkAddToParams(Parameters pin, CanonicalResource cr) {
boolean cache = false;
boolean addToParams = false;
if (tcc.usingCache()) {
if (!tcc.alreadyCached(cr)) {
tcc.addToCache(cr);
System.out.println("add to cache: "+cr.getVUrl());
addToParams = true;
cache = true;
} else {
System.out.println("already cached: "+cr.getVUrl());
}
} else {
addToParams = true;
}
if (addToParams) {
pin.addParameter().setName("tx-resource").setResource(cr);
}
return cache;
}
private boolean hasCanonicalResource(Parameters pin, String name, String vUrl) {
for (ParametersParameterComponent p : pin.getParameter()) {
if (name.equals(p.getName()) && p.hasResource() &&

View File

@ -3,7 +3,9 @@ package org.hl7.fhir.r5.terminologies.client;
import java.util.HashSet;
import java.util.Set;
import org.hl7.fhir.r5.model.CanonicalResource;
import org.hl7.fhir.r5.model.TerminologyCapabilities;
import org.hl7.fhir.r5.model.ValueSet;
public class TerminologyClientContext {
private String cacheId;
@ -76,6 +78,18 @@ public class TerminologyClientContext {
}
public boolean usingCache() {
return isTxCaching && cacheId != null;
}
public boolean alreadyCached(CanonicalResource cr) {
return cached.contains(cr.getVUrl());
}
public void addToCache(CanonicalResource cr) {
cached.add(cr.getVUrl());
}
}