From dbb8470b80c51ec0f67e3a8d63e24ada64eaefb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Tue, 5 Aug 2025 22:26:30 +0200 Subject: [PATCH] Make GlobalCache facade not cached. Even though it wasn't causing issues in our existing tests, it likely was flaky, and making it not $cached makes it now consistent with global_cache() - always getting a new CacheManager from the globalCache container binding --- src/Facades/GlobalCache.php | 3 +++ src/TenancyServiceProvider.php | 1 - tests/GlobalCacheTest.php | 9 ++++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Facades/GlobalCache.php b/src/Facades/GlobalCache.php index b8b5ce99..d1a182aa 100644 --- a/src/Facades/GlobalCache.php +++ b/src/Facades/GlobalCache.php @@ -8,6 +8,9 @@ use Illuminate\Support\Facades\Cache; class GlobalCache extends Cache { + /** Make sure this works identically to global_cache() */ + protected static $cached = false; + protected static function getFacadeAccessor() { return 'globalCache'; diff --git a/src/TenancyServiceProvider.php b/src/TenancyServiceProvider.php index 1c2e1abe..6e26a953 100644 --- a/src/TenancyServiceProvider.php +++ b/src/TenancyServiceProvider.php @@ -83,7 +83,6 @@ class TenancyServiceProvider extends ServiceProvider return new Commands\Seed($app['db']); }); - // todo0 check how the caching in the facade affects our logic here // todo0 check what happens if globalCache is injected - it may be // problematic if it's injected before adjustCacheManagerUsing // was used diff --git a/tests/GlobalCacheTest.php b/tests/GlobalCacheTest.php index 42283ddf..d166bdc9 100644 --- a/tests/GlobalCacheTest.php +++ b/tests/GlobalCacheTest.php @@ -68,6 +68,14 @@ test('global cache manager stores data in global cache', function (string $boots CacheTenancyBootstrapper::class, ]); +test('global cache facade is not persistent', function () { + $oldId = spl_object_id(GlobalCache::getFacadeRoot()); + + $_ = new class {}; + + expect(spl_object_id(GlobalCache::getFacadeRoot()))->not()->toBe($oldId); +}); + test('global cache is always central', function (string $store, array $bootstrappers, string $initialCentralCall) { config([ 'cache.default' => $store, @@ -130,7 +138,6 @@ test('global cache is always central', function (string $store, array $bootstrap expect(global_cache('central-facade'))->toBe(true); expect(GlobalCache::get('central-facade'))->toBe(true); } - })->with([ ['redis', [CacheTagsBootstrapper::class]], ['redis', [CacheTenancyBootstrapper::class]],