From e7cce6ab43dfe881fcc43cfc119160350445cd0d Mon Sep 17 00:00:00 2001 From: Julian Hundeloh <5358638+jaulz@users.noreply.github.com> Date: Mon, 25 Nov 2024 20:04:55 +0100 Subject: [PATCH] feat: write cache in separate method --- src/Resolvers/Contracts/CachedTenantResolver.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Resolvers/Contracts/CachedTenantResolver.php b/src/Resolvers/Contracts/CachedTenantResolver.php index feb9609c..593ae51b 100644 --- a/src/Resolvers/Contracts/CachedTenantResolver.php +++ b/src/Resolvers/Contracts/CachedTenantResolver.php @@ -34,20 +34,25 @@ abstract class CachedTenantResolver implements TenantResolver return $this->resolveWithoutCache(...$args); } - $key = $this->getCacheKey(...$args); - - if ($tenant = $this->cache->get($key)) { + if ($tenant = $this->cache->get($this->getCacheKey(...$args))) { $this->resolved($tenant, ...$args); return $tenant; } - $tenant = $this->resolveWithoutCache(...$args); - $this->cache->put($key, $tenant, static::$cacheTTL); + $this->writeCache(...$args); 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 { if (! static::$shouldCache) {