From 1cd3e3392720682661097a890b485b6e50feb5ae Mon Sep 17 00:00:00 2001 From: Daniel Jones Date: Fri, 13 Nov 2026 22:38:44 +0000 Subject: [PATCH 1/2] Keep which indexes are used when the Stache is cleared --- src/Stache/Stores/Store.php | 4 ++-- tests/Stache/StoreTest.php | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Stache/Stores/Store.php b/src/Stache/Stores/Store.php index ee31e4236a9..c9a21e91fe5 100644 --- a/src/Stache/Stores/Store.php +++ b/src/Stache/Stores/Store.php @@ -406,8 +406,8 @@ public function clear() app('stache.indexes')->forget("{$this->key()}.{$index->name()}"); }); - $this->usedIndexes = collect(); - Stache::cacheStore()->forget($this->indexUsageCacheKey()); + // Which indexes queries use is kept. It's what tells the next warm to build them, + // rather than leaving the first requests to build each one from every item. $this->clearCachedPaths(); diff --git a/tests/Stache/StoreTest.php b/tests/Stache/StoreTest.php index 503b5b08c05..567d2e7a495 100644 --- a/tests/Stache/StoreTest.php +++ b/tests/Stache/StoreTest.php @@ -125,6 +125,22 @@ public function index_usage_cached_by_another_process_is_kept() $this->assertEquals(['path', 'site', 'uri'], Cache::get($cacheKey)); } + + #[Test] + public function clearing_keeps_which_indexes_are_used_so_the_next_warm_builds_them() + { + $cacheKey = "stache::indexes::{$this->store->key()}::_indexes"; + + $this->store->cacheIndexUsage('title'); + + $this->store->clear(); + + $this->assertEquals(['title'], Cache::get($cacheKey)); + $this->assertTrue($this->store->indexes()->has('title')); + + // A process that starts after the clear, as the one that warms usually is. + $this->assertTrue((new TestStore)->indexes()->has('title')); + } } class TestStore extends Store From 154af9adda16736e7026d38c2862d685f74fd362 Mon Sep 17 00:00:00 2001 From: Daniel Jones Date: Sat, 14 Nov 2026 00:41:44 +0000 Subject: [PATCH 2/2] Test that an index used again after clearing is still recorded --- tests/Stache/StoreTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/Stache/StoreTest.php b/tests/Stache/StoreTest.php index 567d2e7a495..a95548bf03d 100644 --- a/tests/Stache/StoreTest.php +++ b/tests/Stache/StoreTest.php @@ -141,6 +141,23 @@ public function clearing_keeps_which_indexes_are_used_so_the_next_warm_builds_th // A process that starts after the clear, as the one that warms usually is. $this->assertTrue((new TestStore)->indexes()->has('title')); } + + #[Test] + public function an_index_used_again_after_clearing_is_still_recorded() + { + // Asset containers are cleared on every request when the watcher is on, and use + // their path index straight after. See https://github.com/statamic/cms/issues/3476 + $cacheKey = "stache::indexes::{$this->store->key()}::_indexes"; + + $this->store->cacheIndexUsage('path'); + + $this->store->clear(); + + $this->store->cacheIndexUsage('path'); + + $this->assertEquals(['path'], Cache::get($cacheKey)); + $this->assertTrue((new TestStore)->indexes()->has('path')); + } } class TestStore extends Store