mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 12:54:05 +00:00
Add identification section to config, refactor static properties
This commit is contained in:
parent
e5bc8ddb77
commit
ccaba05272
17 changed files with 153 additions and 97 deletions
|
|
@ -11,23 +11,17 @@ use Stancl\Tenancy\Contracts\TenantResolver;
|
|||
|
||||
abstract class CachedTenantResolver implements TenantResolver
|
||||
{
|
||||
public static bool $shouldCache = false; // todo docblocks for these
|
||||
|
||||
public static int $cacheTTL = 3600; // seconds
|
||||
|
||||
public static string|null $cacheStore = null; // default
|
||||
|
||||
/** @var Repository */
|
||||
protected $cache;
|
||||
|
||||
public function __construct(Factory $cache)
|
||||
{
|
||||
$this->cache = $cache->store(static::$cacheStore);
|
||||
$this->cache = $cache->store(static::cacheStore());
|
||||
}
|
||||
|
||||
public function resolve(mixed ...$args): Tenant
|
||||
{
|
||||
if (! static::$shouldCache) {
|
||||
if (! static::shouldCache()) {
|
||||
return $this->resolveWithoutCache(...$args);
|
||||
}
|
||||
|
||||
|
|
@ -42,14 +36,14 @@ abstract class CachedTenantResolver implements TenantResolver
|
|||
}
|
||||
|
||||
$tenant = $this->resolveWithoutCache(...$args);
|
||||
$this->cache->put($key, $tenant, static::$cacheTTL);
|
||||
$this->cache->put($key, $tenant, static::cacheTTL());
|
||||
|
||||
return $tenant;
|
||||
}
|
||||
|
||||
public function invalidateCache(Tenant $tenant): void
|
||||
{
|
||||
if (! static::$shouldCache) {
|
||||
if (! static::shouldCache()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -75,4 +69,19 @@ abstract class CachedTenantResolver implements TenantResolver
|
|||
* @return array[]
|
||||
*/
|
||||
abstract public function getArgsForTenant(Tenant $tenant): array;
|
||||
|
||||
public static function shouldCache(): bool
|
||||
{
|
||||
return config('tenancy.identification.resolvers.' . static::class . '.cache') ?? false;
|
||||
}
|
||||
|
||||
public static function cacheTTL(): int
|
||||
{
|
||||
return config('tenancy.identification.resolvers.' . static::class . '.cache_ttl') ?? 3600;
|
||||
}
|
||||
|
||||
public static function cacheStore(): string|null
|
||||
{
|
||||
return config('tenancy.identification.resolvers.' . static::class . '.cache_store');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue