From 8fc941b53c5c756438f8bc786f151fae3d0e7ccc Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Tue, 21 Jul 2026 13:17:32 +0100 Subject: [PATCH] Ensure application cache honours static_cache store --- src/StaticCaching/StaticCacheManager.php | 3 +- tests/StaticCaching/ManagerTest.php | 39 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/StaticCaching/StaticCacheManager.php b/src/StaticCaching/StaticCacheManager.php index 3d2879f79b7..1e2156c10d9 100644 --- a/src/StaticCaching/StaticCacheManager.php +++ b/src/StaticCaching/StaticCacheManager.php @@ -2,7 +2,6 @@ namespace Statamic\StaticCaching; -use Illuminate\Cache\Repository; use Illuminate\Support\Facades\Cache; use Statamic\Events\StaticCacheCleared; use Statamic\Facades\Site; @@ -37,7 +36,7 @@ public function createFileDriver(array $config) public function createApplicationDriver(array $config) { - return new ApplicationCacher($this->app[Repository::class], $config); + return new ApplicationCacher($this->cacheStore(), $config); } public function cacheStore() diff --git a/tests/StaticCaching/ManagerTest.php b/tests/StaticCaching/ManagerTest.php index 86d5f8fdbe1..563c2dbacb6 100644 --- a/tests/StaticCaching/ManagerTest.php +++ b/tests/StaticCaching/ManagerTest.php @@ -7,10 +7,49 @@ use PHPUnit\Framework\Attributes\Test; use Statamic\Facades\StaticCache; use Statamic\StaticCaching\Cacher; +use Statamic\StaticCaching\Cachers\ApplicationCacher; use Tests\TestCase; class ManagerTest extends TestCase { + #[Test] + public function application_driver_uses_the_default_cache_store_when_no_custom_store_is_defined() + { + config([ + 'statamic.static_caching.strategy' => 'half', + 'statamic.static_caching.strategies.half.driver' => 'application', + ]); + + $cacher = StaticCache::driver(); + + $this->assertInstanceOf(ApplicationCacher::class, $cacher); + $this->assertSame(Cache::store(), $this->getCacherCache($cacher)); + } + + #[Test] + public function application_driver_uses_the_custom_static_cache_store_when_defined() + { + config([ + 'statamic.static_caching.strategy' => 'half', + 'statamic.static_caching.strategies.half.driver' => 'application', + 'cache.stores.static_cache' => ['driver' => 'array'], + ]); + + $cacher = StaticCache::driver(); + + $this->assertInstanceOf(ApplicationCacher::class, $cacher); + $this->assertSame(Cache::store('static_cache'), $this->getCacherCache($cacher)); + $this->assertNotSame(Cache::store(), $this->getCacherCache($cacher)); + } + + private function getCacherCache(ApplicationCacher $cacher) + { + $property = new \ReflectionProperty($cacher, 'cache'); + $property->setAccessible(true); + + return $property->getValue($cacher); + } + #[Test] public function it_flushes() {