From dc9c8fcf6851656940d8b3afd0a1f6727a6dc3d9 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Mon, 12 Dec 2022 16:58:40 +0100 Subject: [PATCH] Simplify cache store refreshing --- .../PrefixCacheTenancyBootstrapper.php | 21 +------------------ 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/src/Bootstrappers/PrefixCacheTenancyBootstrapper.php b/src/Bootstrappers/PrefixCacheTenancyBootstrapper.php index 1e502e1d..dce58029 100644 --- a/src/Bootstrappers/PrefixCacheTenancyBootstrapper.php +++ b/src/Bootstrappers/PrefixCacheTenancyBootstrapper.php @@ -39,30 +39,11 @@ class PrefixCacheTenancyBootstrapper implements TenancyBootstrapper $this->originalPrefix = null; } - protected function syncStore(): void - { - $originalRepository = $this->cacheManager->driver($this->storeName); - - // Delete the repository from CacheManager's $stores cache - // So that it's forced to resolve the repository again on the next attempt to get it - $this->cacheManager->forgetDriver($this->storeName); - - // Let CacheManager create a repository with a fresh store - // To get a new store that uses the current value of `config('cache.prefix')` as the prefix - $newRepository = $this->cacheManager->driver($this->storeName); - - // Give the new store to the old repository - $originalRepository->setStore($newRepository->getStore()); - - // Overwrite the new repository with the modified old one - $this->cacheManager->setStore($this->storeName, $originalRepository); - } - protected function setCachePrefix(string|null $prefix): void { $this->config->set('cache.prefix', $prefix); - $this->syncStore(); + $this->cacheManager->refreshStore(); // It is needed when a call to the facade has been made before bootstrapping tenancy // The facade has its own cache, separate from the container