mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 19:14:04 +00:00
Add check to invalidateCache()
This commit is contained in:
parent
5d94727ddd
commit
ba7257670f
4 changed files with 89 additions and 45 deletions
|
|
@ -48,6 +48,10 @@ abstract class CachedTenantResolver implements TenantResolver
|
|||
|
||||
public function invalidateCache(Tenant $tenant): void
|
||||
{
|
||||
if (! static::$shouldCache) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($this->getArgsForTenant($tenant) as $args) {
|
||||
$this->cache->forget($this->getCacheKey(...$args));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,12 +6,20 @@ namespace Stancl\Tenancy\Resolvers;
|
|||
|
||||
use Stancl\Tenancy\Contracts\Domain;
|
||||
use Stancl\Tenancy\Contracts\Tenant;
|
||||
use Stancl\Tenancy\Contracts\TenantResolver;
|
||||
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedOnDomainException;
|
||||
|
||||
class DomainTenantResolver implements TenantResolver
|
||||
class DomainTenantResolver extends Contracts\CachedTenantResolver
|
||||
{
|
||||
public function resolve(...$args): Tenant
|
||||
/** @var bool */
|
||||
public static $shouldCache = false;
|
||||
|
||||
/** @var int */
|
||||
public static $cacheTTL = 3600; // seconds
|
||||
|
||||
/** @var string|null */
|
||||
public static $cacheStore = null; // default
|
||||
|
||||
public function resolveWithoutCache(...$args): Tenant
|
||||
{
|
||||
/** @var Domain $domain */
|
||||
$domain = config('tenancy.domain_model')::where('domain', $args[0])->first();
|
||||
|
|
@ -22,4 +30,13 @@ class DomainTenantResolver implements TenantResolver
|
|||
|
||||
throw new TenantCouldNotBeIdentifiedOnDomainException($domain);
|
||||
}
|
||||
|
||||
public function getArgsForTenant(Tenant $tenant): array
|
||||
{
|
||||
$tenant->unsetRelation('domains');
|
||||
|
||||
return $tenant->domains->map(function (Domain $domain) {
|
||||
return [$domain->domain];
|
||||
})->toArray();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class PostgreSQLSchemaManager implements TenantDatabaseManager
|
|||
|
||||
public function deleteDatabase(TenantWithDatabase $tenant): bool
|
||||
{
|
||||
return $this->database()->statement("DROP SCHEMA \"{$tenant->database()->getName()}\"");
|
||||
return $this->database()->statement("DROP SCHEMA \"{$tenant->database()->getName()}\" CASCADE");
|
||||
}
|
||||
|
||||
public function databaseExists(string $name): bool
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue