1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 10:14:04 +00:00

Separate data & domains logic

This commit is contained in:
Samuel Štancl 2020-03-14 19:36:28 +01:00
parent a86412af09
commit 0deb1f1376
2 changed files with 10 additions and 6 deletions

View file

@ -34,12 +34,14 @@ class CachedTenantResolver
return $this->cache->remember('_tenancy_domain_to_id:' . $domain, $this->ttl(), $query);
}
public function findById(string $id, Closure $dataQuery, Closure $domainsQuery): Tenant
public function getDataById(string $id, Closure $dataQuery): ?array
{
$data = $this->cache->remember('_tenancy_id_to_data:' . $id, $this->ttl(), $dataQuery);
$domains = $this->cache->remember('_tenancy_id_to_domains:' . $id, $this->ttl(), $domainsQuery);
return $this->cache->remember('_tenancy_id_to_data:' . $id, $this->ttl(), $dataQuery);
}
return Tenant::fromStorage($data)->withDomains($domains);
public function getDomainsById(string $id, Closure $domainsQuery): ?array
{
return $this->cache->remember('_tenancy_id_to_domains:' . $id, $this->ttl(), $domainsQuery);
}
public function invalidateTenant(string $id): void

View file

@ -91,9 +91,11 @@ class DatabaseStorageDriver implements StorageDriver, CanDeleteKeys, CanFindByAn
};
if ($this->usesCache()) {
return $this->cache->findById($id, $dataQuery, $domainsQuery);
$data = $this->cache->getDataById($id, $dataQuery);
$domains = $this->cache->getDomainsById($id, $domainsQuery);
} else {
$data = $dataQuery();
$domains = $domainsQuery();
}
if (! $data) {
@ -101,7 +103,7 @@ class DatabaseStorageDriver implements StorageDriver, CanDeleteKeys, CanFindByAn
}
return Tenant::fromStorage($data)
->withDomains($domainsQuery());
->withDomains($domains);
}
/**