diff --git a/dev/README.md b/dev/README.md
index da26e4c..7c44fe7 100644
--- a/dev/README.md
+++ b/dev/README.md
@@ -30,6 +30,7 @@ Production installs use the default-enabled optimizations. These switches suppor
| `tax_rates` | Tax rates and applied rates per rate request from the cache, for requests that are not customer-specific. | Yes |
| `customer_groups` | Customer groups by id from the cache, with their excluded websites. | Yes |
| `currency_rates` | Currency rates from the cache; a rate import cleans them. | Yes |
+| `directory_data` | The directory section (countries, regions) per store view from the cache; a config save or a translation change cleans it. | Yes |
| `config_memo` | The configuration values a request read, by scope, scope code and path; a clean, a mutable set and a store switch empty it. | No |
| `stock_id` | The stock id of the current website from the cache; a change of a stock's sales channels cleans it. | Yes |
diff --git a/src/FastBoot/Plugin/Directory/DirectoryDataFromCache.php b/src/FastBoot/Plugin/Directory/DirectoryDataFromCache.php
new file mode 100644
index 0000000..3c2a308
--- /dev/null
+++ b/src/FastBoot/Plugin/Directory/DirectoryDataFromCache.php
@@ -0,0 +1,47 @@
+feature->on(self::SWITCH)) {
+ return $proceed();
+ }
+ $key = self::KEY . (int)$this->storeManager->getStore()->getId();
+ $cached = $this->cache->load($key);
+ $data = is_string($cached) ? json_decode($cached, true) : null;
+ if (is_array($data)) {
+ return $data;
+ }
+ $data = $proceed();
+ $this->cache->save(json_encode($data), $key, [ConfigCache::CACHE_TAG, TranslateCache::CACHE_TAG]);
+
+ return $data;
+ }
+}
diff --git a/src/FastBoot/Test/Unit/Plugin/Directory/DirectoryDataFromCacheTest.php b/src/FastBoot/Test/Unit/Plugin/Directory/DirectoryDataFromCacheTest.php
new file mode 100644
index 0000000..4ec5705
--- /dev/null
+++ b/src/FastBoot/Test/Unit/Plugin/Directory/DirectoryDataFromCacheTest.php
@@ -0,0 +1,77 @@
+createMock(CacheInterface::class);
+ $cache->method('load')->willReturnCallback(fn(string $id) => $this->entries[$id] ?? false);
+ $cache->method('save')->willReturnCallback(function (string $data, string $id, array $tags) {
+ $this->entries[$id] = $data;
+ $this->tags[$id] = $tags;
+
+ return true;
+ });
+ $feature = $this->createStub(Feature::class);
+ $feature->method('on')->willReturn($on);
+ $store = $this->createStub(StoreInterface::class);
+ $store->method('getId')->willReturnCallback(fn() => $this->storeId);
+ $stores = $this->createStub(StoreManagerInterface::class);
+ $stores->method('getStore')->willReturn($store);
+
+ return new DirectoryDataFromCache($cache, $feature, $stores);
+ }
+
+ public function testTheSectionIsComputedOncePerStoreView(): void
+ {
+ $plugin = $this->plugin();
+ $subject = $this->createStub(DirectoryData::class);
+ $calls = 0;
+ $proceed = function () use (&$calls) {
+ $calls++;
+
+ return ['NL' => ['name' => 'Netherlands' . $calls, 'regions' => [12 => ['code' => 'NH', 'name' => 'Noord-Holland']]]];
+ };
+
+ $first = $plugin->aroundGetSectionData($subject, $proceed);
+ self::assertSame($first, $plugin->aroundGetSectionData($subject, $proceed));
+ self::assertSame(1, $calls);
+ self::assertSame('Noord-Holland', $first['NL']['regions'][12]['name']);
+ self::assertSame(['CONFIG', 'TRANSLATE'], $this->tags['FASTBOOT_DIRECTORY_DATA_1']);
+
+ $this->storeId = 2;
+ self::assertSame('Netherlands2', $plugin->aroundGetSectionData($subject, $proceed)['NL']['name']);
+ self::assertSame(2, $calls);
+ }
+
+ public function testTheSwitchOffComputesEveryTime(): void
+ {
+ $plugin = $this->plugin(false);
+ $calls = 0;
+ $proceed = function () use (&$calls) {
+ $calls++;
+
+ return [];
+ };
+ $plugin->aroundGetSectionData($this->createStub(DirectoryData::class), $proceed);
+ $plugin->aroundGetSectionData($this->createStub(DirectoryData::class), $proceed);
+
+ self::assertSame(2, $calls);
+ self::assertSame([], $this->entries);
+ }
+}
diff --git a/src/FastBoot/etc/di.xml b/src/FastBoot/etc/di.xml
index 130c3f6..afa31ab 100644
--- a/src/FastBoot/etc/di.xml
+++ b/src/FastBoot/etc/di.xml
@@ -10,6 +10,7 @@
- FASTBOOT_TAX_RATE_
- FASTBOOT_GROUP_
- FASTBOOT_CURRENCY_RATE_
+ - FASTBOOT_DIRECTORY_DATA_
- GraphCommerce\FastBootCache\Model\Tag::TAX
@@ -80,6 +81,9 @@
+
+
+
diff --git a/src/FastBoot/etc/module.xml b/src/FastBoot/etc/module.xml
index 6ea29ec..6ac0c4e 100644
--- a/src/FastBoot/etc/module.xml
+++ b/src/FastBoot/etc/module.xml
@@ -10,6 +10,7 @@
+
diff --git a/src/FastBootCache/Model/Feature.php b/src/FastBootCache/Model/Feature.php
index abcf41b..6be3ad0 100644
--- a/src/FastBootCache/Model/Feature.php
+++ b/src/FastBootCache/Model/Feature.php
@@ -15,7 +15,7 @@
class Feature
{
private ?array $switches = null;
- private const CACHED = ['schema_array' => true,'cache_files' => true,'system_config_array' => true,'view_config' => true,'parsed_queries' => true,'validated_queries' => true,'scopes_cache' => true,'website_stores' => true,'deploy_config_unchanged' => true,'placeholder_url' => true,'guest_tax_factor' => true,'tax_rates' => true,'customer_groups' => true,'currency_rates' => true,'stock_id' => true];
+ private const CACHED = ['schema_array' => true,'cache_files' => true,'system_config_array' => true,'view_config' => true,'parsed_queries' => true,'validated_queries' => true,'scopes_cache' => true,'website_stores' => true,'deploy_config_unchanged' => true,'placeholder_url' => true,'guest_tax_factor' => true,'tax_rates' => true,'customer_groups' => true,'currency_rates' => true,'directory_data' => true,'stock_id' => true];
public function __construct(
private readonly DeploymentConfig $deploymentConfig,