1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 20:34:03 +00:00

feat: write cache in separate method

This commit is contained in:
Julian Hundeloh 2024-11-25 20:04:55 +01:00 committed by GitHub
parent 30cdc9461e
commit e7cce6ab43
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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) {