mirror of
https://github.com/hapifhir/org.hl7.fhir.core.git
synced 2025-02-10 06:44:44 +00:00
Better cache control
This commit is contained in:
parent
0b18b3a3b3
commit
84edac9abe
@ -1500,26 +1500,39 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
|
|||||||
for (CanonicalType c : inc.getValueSet()) {
|
for (CanonicalType c : inc.getValueSet()) {
|
||||||
ValueSet vs = fetchResource(ValueSet.class, c.getValue(), src);
|
ValueSet vs = fetchResource(ValueSet.class, c.getValue(), src);
|
||||||
if (vs != null && !hasCanonicalResource(pin, "tx-resource", vs.getVUrl())) {
|
if (vs != null && !hasCanonicalResource(pin, "tx-resource", vs.getVUrl())) {
|
||||||
pin.addParameter().setName("tx-resource").setResource(vs);
|
cache = checkAddToParams(pin, vs) || cache;
|
||||||
if (tcc.isTxCaching() && tcc.getCacheId() == null || !tcc.getCached().contains(vs.getVUrl())) {
|
|
||||||
tcc.getCached().add(vs.getVUrl());
|
|
||||||
cache = true;
|
|
||||||
}
|
|
||||||
addDependentResources(pin, vs);
|
addDependentResources(pin, vs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CodeSystem cs = fetchResource(CodeSystem.class, inc.getSystem(), src);
|
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)) {
|
if (cs != null && !hasCanonicalResource(pin, "tx-resource", cs.getVUrl()) && (cs.getContent() == CodeSystemContentMode.COMPLETE || cs.getContent() == CodeSystemContentMode.FRAGMENT)) {
|
||||||
pin.addParameter().setName("tx-resource").setResource(cs);
|
cache = checkAddToParams(pin, cs) || cache;
|
||||||
if (tcc.isTxCaching() && tcc.getCacheId() == null || !tcc.getCached().contains(cs.getVUrl())) {
|
|
||||||
tcc.getCached().add(cs.getVUrl());
|
|
||||||
cache = true;
|
|
||||||
}
|
|
||||||
// todo: supplements
|
// todo: supplements
|
||||||
}
|
}
|
||||||
return cache;
|
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) {
|
private boolean hasCanonicalResource(Parameters pin, String name, String vUrl) {
|
||||||
for (ParametersParameterComponent p : pin.getParameter()) {
|
for (ParametersParameterComponent p : pin.getParameter()) {
|
||||||
if (name.equals(p.getName()) && p.hasResource() &&
|
if (name.equals(p.getName()) && p.hasResource() &&
|
||||||
|
@ -3,7 +3,9 @@ package org.hl7.fhir.r5.terminologies.client;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.hl7.fhir.r5.model.CanonicalResource;
|
||||||
import org.hl7.fhir.r5.model.TerminologyCapabilities;
|
import org.hl7.fhir.r5.model.TerminologyCapabilities;
|
||||||
|
import org.hl7.fhir.r5.model.ValueSet;
|
||||||
|
|
||||||
public class TerminologyClientContext {
|
public class TerminologyClientContext {
|
||||||
private String cacheId;
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user