Skip to content

Commit f94adcb

Browse files
committed
Add config caching in PxWebDriver
1 parent ff77318 commit f94adcb

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
1010
### Added
1111

1212
- ![SOURCE] Add source from Swiss Federal Statistical Office [#1132](https://github.com/nbbrd/sdmx-dl/issues/1132)
13+
- ![PROVIDER] Add config caching in PxWebDriver
1314
- ![GRPC] Add simple web page to query rest web service
1415
- ![CLI] Add option to set system properties from command-line
1516
- ![CLI] Add experimental list upptime command
1617

1718
### Fixed
1819

1920
- ![SOURCE] Update NBB source [#1133](https://github.com/nbbrd/sdmx-dl/issues/1133)
20-
- ![SOURCE] Fix source links in PxWebDriver
21+
- ![PROVIDER] Fix source links in PxWebDriver
2122
- ![GRPC] Fix aliases when listing sources
2223

2324
## [3.0.0-beta.16] - 2025-11-13

sdmx-dl-provider-px/src/main/java/sdmxdl/provider/px/drivers/PxWebDriver.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,9 @@ private static final class CachedPxWebClient implements PxWebClient {
389389
@lombok.NonNull
390390
private final Duration ttl;
391391

392+
@lombok.Getter(lazy = true)
393+
private final TypedId<Config> idOfConfig = initIdOfConfig(baseURI);
394+
392395
@lombok.Getter(lazy = true)
393396
private final TypedId<List<sdmxdl.Database>> idOfDatabases = initIdOfDatabases(baseURI);
394397

@@ -398,6 +401,13 @@ private static final class CachedPxWebClient implements PxWebClient {
398401
@lombok.Getter(lazy = true)
399402
private final TypedId<Structure> idOfMeta = initIdOfMeta(baseURI);
400403

404+
private static TypedId<Config> initIdOfConfig(URI base) {
405+
return TypedId.of(base,
406+
repo -> Config.JSON_PARSER.asParser().parse(repo.getName()),
407+
config -> DataRepository.builder().name(Config.JSON_FORMATTER.asFormatter().formatValueAsString(config).orElse("")).build()
408+
).with("config");
409+
}
410+
401411
private static TypedId<List<sdmxdl.Database>> initIdOfDatabases(URI base) {
402412
return TypedId.of(base,
403413
DataRepository::getDatabases,
@@ -431,7 +441,8 @@ private static TypedId<Structure> initIdOfMeta(URI base) {
431441

432442
@Override
433443
public @NonNull Config getConfig() throws IOException {
434-
return delegate.getConfig();
444+
return getIdOfConfig()
445+
.load(cache, delegate::getConfig, ignore -> ttl);
435446
}
436447

437448
@Override
@@ -613,6 +624,21 @@ static Config deserialize(JsonElement json, Type typeOfT, JsonDeserializationCon
613624
x.get("timeWindow").getAsInt()
614625
);
615626
}
627+
628+
static final TextFormatter<Config> JSON_FORMATTER = GsonIO.GsonFormatter
629+
.builder(Config.class)
630+
.serializer(Config.class, Config::serialize)
631+
.build();
632+
633+
@MightBeGenerated
634+
static JsonElement serialize(Config src, Type typeOfSrc, JsonSerializationContext context) {
635+
JsonObject result = new JsonObject();
636+
result.addProperty("maxValues", src.maxValues);
637+
result.addProperty("maxCells", src.maxCells);
638+
result.addProperty("maxCalls", src.maxCalls);
639+
result.addProperty("timeWindow", src.timeWindow);
640+
return result;
641+
}
616642
}
617643

618644
@VisibleForTesting

sdmx-dl-provider-px/src/test/java/sdmxdl/provider/px/drivers/PxWebDriverTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@ public void testCompliance() {
2828

2929
@Test
3030
public void testConfig() throws IOException {
31+
Config sample = new Config(120000, 120012, 30, 10);
32+
3133
assertThat(PxWebDriver.Config.JSON_PARSER.parseResource(PxWebDriverTest.class, "statfin-config.json", UTF_8))
32-
.isEqualTo(new PxWebDriver.Config(120000, 120000, 30, 10));
34+
.isEqualTo(sample);
35+
36+
assertThat(Config.JSON_PARSER.parseChars(PxWebDriver.Config.JSON_FORMATTER.formatToString(sample)))
37+
.isEqualTo(sample);
3338
}
3439

3540
@Test

sdmx-dl-provider-px/src/test/resources/sdmxdl/provider/px/drivers/statfin-config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"maxValues": 120000,
3-
"maxCells": 120000,
3+
"maxCells": 120012,
44
"maxCalls": 30,
55
"timeWindow": 10,
66
"CORS": true

0 commit comments

Comments
 (0)