diff --git a/src/Bootstrappers/PrefixCacheTenancyBootstrapper.php b/src/Bootstrappers/PrefixCacheTenancyBootstrapper.php index dce58029..86c83bd2 100644 --- a/src/Bootstrappers/PrefixCacheTenancyBootstrapper.php +++ b/src/Bootstrappers/PrefixCacheTenancyBootstrapper.php @@ -23,10 +23,6 @@ class PrefixCacheTenancyBootstrapper implements TenancyBootstrapper public function bootstrap(Tenant $tenant): void { - Cache::macro('setStore', function ($store) { - $this->store = $store; - }); - $this->originalPrefix = $this->config->get('cache.prefix'); $this->storeName = $this->config->get('cache.default'); diff --git a/src/CacheManager.php b/src/CacheManager.php index f80cd017..ce39d239 100644 --- a/src/CacheManager.php +++ b/src/CacheManager.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Stancl\Tenancy; +use Illuminate\Support\Facades\Cache; use Illuminate\Cache\CacheManager as BaseCacheManager; // todo move to Cache namespace? @@ -43,6 +44,10 @@ class CacheManager extends BaseCacheManager public function refreshStore(string|null $repository = null): void { + Cache::macro('setStore', function ($store) { + $this->store = $store; + }); + $newStore = $this->resolve($repository ?? $this->getDefaultDriver())->getStore(); $this->driver($repository)->setStore($newStore);