mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 15:54:03 +00:00
Fix some tests
This commit is contained in:
parent
800e8d5a56
commit
dce06b7430
1 changed files with 11 additions and 10 deletions
|
|
@ -4,16 +4,16 @@ declare(strict_types=1);
|
|||
|
||||
namespace Stancl\Tenancy\Resolvers;
|
||||
|
||||
use Illuminate\Cache\Repository;
|
||||
use Illuminate\Contracts\Cache\Factory;
|
||||
use Stancl\Tenancy\Contracts\Tenant;
|
||||
use Stancl\Tenancy\Contracts\TenantResolver;
|
||||
|
||||
class CachedTenantResolver implements TenantResolver
|
||||
{
|
||||
/** @var Repository */
|
||||
/** @var CacheManager */
|
||||
protected $cache;
|
||||
|
||||
public function __construct(Repository $cache)
|
||||
public function __construct(Factory $cache)
|
||||
{
|
||||
$this->cache = $cache;
|
||||
}
|
||||
|
|
@ -22,20 +22,21 @@ class CachedTenantResolver implements TenantResolver
|
|||
{
|
||||
$resolverClass = $args[0];
|
||||
$data = $args[1];
|
||||
$ttl = $args[2];
|
||||
$cacheStore = $args[3];
|
||||
$ttl = $args[2] ?? null;
|
||||
$cacheStore = $args[3] ?? null;
|
||||
|
||||
/** @var TenantResolver $resolver */
|
||||
$resolver = app($resolverClass);
|
||||
$encodedData = json_encode($data);
|
||||
|
||||
if ($this->cache->has($key = "_tenancy_resolver:$resolverClass:$encodedData")) {
|
||||
return $this->cache->get($key);
|
||||
$cache = $this->cache->store($cacheStore);
|
||||
|
||||
if ($cache->has($key = "_tenancy_resolver:$resolverClass:$encodedData")) {
|
||||
return $cache->get($key);
|
||||
}
|
||||
|
||||
$this->cache->put($key,
|
||||
$resolved = $resolver->resolve(...$data)
|
||||
);
|
||||
$resolved = $resolver->resolve(...$data);
|
||||
$cache->put($key, $resolved, $ttl);
|
||||
|
||||
return $resolved;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue