mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-14 09:44:03 +00:00
Simplify cache store refreshing
This commit is contained in:
parent
012a39f79d
commit
dc9c8fcf68
1 changed files with 1 additions and 20 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue