mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 17:14:03 +00:00
feat: write cache in separate method
This commit is contained in:
parent
30cdc9461e
commit
e7cce6ab43
1 changed files with 10 additions and 5 deletions
|
|
@ -34,20 +34,25 @@ abstract class CachedTenantResolver implements TenantResolver
|
||||||
return $this->resolveWithoutCache(...$args);
|
return $this->resolveWithoutCache(...$args);
|
||||||
}
|
}
|
||||||
|
|
||||||
$key = $this->getCacheKey(...$args);
|
if ($tenant = $this->cache->get($this->getCacheKey(...$args))) {
|
||||||
|
|
||||||
if ($tenant = $this->cache->get($key)) {
|
|
||||||
$this->resolved($tenant, ...$args);
|
$this->resolved($tenant, ...$args);
|
||||||
|
|
||||||
return $tenant;
|
return $tenant;
|
||||||
}
|
}
|
||||||
|
|
||||||
$tenant = $this->resolveWithoutCache(...$args);
|
$this->writeCache(...$args);
|
||||||
$this->cache->put($key, $tenant, static::$cacheTTL);
|
|
||||||
|
|
||||||
return $tenant;
|
return $tenant;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function writeCache(...$args): void
|
||||||
|
{
|
||||||
|
$key = $this->getCacheKey(...$args);
|
||||||
|
$tenant = $this->resolveWithoutCache(...$args);
|
||||||
|
|
||||||
|
$this->cache->put($key, $tenant, static::$cacheTTL);
|
||||||
|
}
|
||||||
|
|
||||||
public function invalidateCache(Tenant $tenant): void
|
public function invalidateCache(Tenant $tenant): void
|
||||||
{
|
{
|
||||||
if (! static::$shouldCache) {
|
if (! static::$shouldCache) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue