1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 22:14:03 +00:00

Rewrite cached resolver logic to allow for cache invalidation logic

This commit is contained in:
Samuel Štancl 2020-06-02 20:10:17 +02:00
parent b176481cdf
commit 5d94727ddd
15 changed files with 189 additions and 117 deletions

View file

@ -14,15 +14,6 @@ abstract class IdentificationMiddleware
/** @var callable */
public static $onFail;
/** @var bool */
public static $shouldCache = false;
/** @var int */
public static $cacheTTL = 3600; // seconds
/** @var string|null */
public static $cacheStore = null; // default
/** @var Tenancy */
protected $tenancy;
@ -32,15 +23,9 @@ abstract class IdentificationMiddleware
public function initializeTenancy($request, $next, ...$resolverArguments)
{
try {
if (static::$shouldCache) {
app(CachedTenantResolver::class)->resolve(
get_class($this->resolver), $resolverArguments, static::$cacheTTL, static::$cacheStore
);
} else {
$this->tenancy->initialize(
$this->resolver->resolve(...$resolverArguments)
);
}
$this->tenancy->initialize(
$this->resolver->resolve(...$resolverArguments)
);
} catch (TenantCouldNotBeIdentifiedException $e) {
$onFail = static::$onFail ?? function ($e) {
throw $e;

View file

@ -13,15 +13,6 @@ class InitializeTenancyByDomain extends IdentificationMiddleware
/** @var callable|null */
public static $onFail;
/** @var bool */
public static $shouldCache = false;
/** @var int */
public static $cacheTTL = 3600; // seconds
/** @var string|null */
public static $cacheStore = null; // default
/** @var Tenancy */
protected $tenancy;

View file

@ -16,15 +16,6 @@ class InitializeTenancyByPath extends IdentificationMiddleware
/** @var callable|null */
public static $onFail;
/** @var bool */
public static $shouldCache = false;
/** @var int */
public static $cacheTTL = 3600; // seconds
/** @var string|null */
public static $cacheStore = null; // default
/** @var Tenancy */
protected $tenancy;

View file

@ -20,15 +20,6 @@ class InitializeTenancyByRequestData extends IdentificationMiddleware
/** @var callable|null */
public static $onFail;
/** @var bool */
public static $shouldCache = false;
/** @var int */
public static $cacheTTL = 3600; // seconds
/** @var string|null */
public static $cacheStore = null; // default
/** @var Tenancy */
protected $tenancy;

View file

@ -26,15 +26,6 @@ class InitializeTenancyBySubdomain extends InitializeTenancyByDomain
/** @var callable|null */
public static $onFail;
/** @var bool */
public static $shouldCache = false;
/** @var int */
public static $cacheTTL = 3600; // seconds
/** @var string|null */
public static $cacheStore = null; // default
/**
* Handle an incoming request.
*