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

Disable cache tagging by default, add CacheTagBootstrapper

This commit is contained in:
lukinovec 2023-04-11 14:28:28 +02:00
parent 5849afa4c8
commit 7ebfc375d6
5 changed files with 31 additions and 12 deletions

View file

@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Bootstrappers;
use Stancl\Tenancy\CacheManager;
use Stancl\Tenancy\Contracts\Tenant;
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
class CacheTagBootstrapper implements TenancyBootstrapper
{
public function bootstrap(Tenant $tenant): void
{
CacheManager::$addTags = true;
}
public function revert(): void
{
CacheManager::$addTags = false;
}
}

View file

@ -10,7 +10,7 @@ use Illuminate\Cache\CacheManager as BaseCacheManager;
class CacheManager extends BaseCacheManager class CacheManager extends BaseCacheManager
{ {
public static bool $addTags = true; public static bool $addTags = false;
/** /**
* Add tags and forward the call to the inner cache store. * Add tags and forward the call to the inner cache store.

View file

@ -7,7 +7,6 @@ use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\URL; use Illuminate\Support\Facades\URL;
use Stancl\JobPipeline\JobPipeline; use Stancl\JobPipeline\JobPipeline;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\File;
use Stancl\Tenancy\Bootstrappers\PrefixCacheTenancyBootstrapper;
use Stancl\Tenancy\Tests\Etc\Tenant; use Stancl\Tenancy\Tests\Etc\Tenant;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Event;
@ -29,6 +28,7 @@ use Stancl\Tenancy\Listeners\BootstrapTenancy;
use Stancl\Tenancy\Tests\Etc\TestingBroadcaster; use Stancl\Tenancy\Tests\Etc\TestingBroadcaster;
use Stancl\Tenancy\Listeners\DeleteTenantStorage; use Stancl\Tenancy\Listeners\DeleteTenantStorage;
use Stancl\Tenancy\Listeners\RevertToCentralContext; use Stancl\Tenancy\Listeners\RevertToCentralContext;
use Stancl\Tenancy\Bootstrappers\CacheTagBootstrapper;
use Stancl\Tenancy\Bootstrappers\UrlTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\UrlTenancyBootstrapper;
use Stancl\Tenancy\Bootstrappers\MailTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\MailTenancyBootstrapper;
use Stancl\Tenancy\Bootstrappers\RedisTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\RedisTenancyBootstrapper;
@ -36,7 +36,6 @@ use Stancl\Tenancy\Middleware\InitializeTenancyBySubdomain;
use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper;
use Stancl\Tenancy\Bootstrappers\BroadcastTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\BroadcastTenancyBootstrapper;
use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper; use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper;
use Stancl\Tenancy\CacheManager;
beforeEach(function () { beforeEach(function () {
$this->mockConsoleOutput = false; $this->mockConsoleOutput = false;
@ -84,11 +83,9 @@ test('database data is separated', function () {
}); });
test('cache data is separated', function () { test('cache data is separated', function () {
CacheManager::$addTags = true;
config([ config([
'tenancy.bootstrappers' => [ 'tenancy.bootstrappers' => [
PrefixCacheTenancyBootstrapper::class, CacheTagBootstrapper::class,
], ],
'cache.default' => 'redis', 'cache.default' => 'redis',
]); ]);

View file

@ -2,16 +2,15 @@
declare(strict_types=1); declare(strict_types=1);
use Stancl\Tenancy\CacheManager;
use Stancl\Tenancy\Tests\Etc\Tenant; use Stancl\Tenancy\Tests\Etc\Tenant;
use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Event;
use Stancl\Tenancy\Events\TenancyInitialized; use Stancl\Tenancy\Events\TenancyInitialized;
use Stancl\Tenancy\Listeners\BootstrapTenancy; use Stancl\Tenancy\Listeners\BootstrapTenancy;
use Stancl\Tenancy\Bootstrappers\CacheTagBootstrapper;
beforeEach(function () { beforeEach(function () {
config(['tenancy.bootstrappers' => []]); config(['tenancy.bootstrappers' => [CacheTagBootstrapper::class]]);
CacheManager::$addTags = true;
Event::listen(TenancyInitialized::class, BootstrapTenancy::class); Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
}); });

View file

@ -2,16 +2,17 @@
declare(strict_types=1); declare(strict_types=1);
use Stancl\Tenancy\Tests\Etc\Tenant;
use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Event;
use Stancl\Tenancy\Events\TenancyEnded; use Stancl\Tenancy\Events\TenancyEnded;
use Stancl\Tenancy\Events\TenancyInitialized;
use Stancl\Tenancy\Facades\GlobalCache; use Stancl\Tenancy\Facades\GlobalCache;
use Stancl\Tenancy\Events\TenancyInitialized;
use Stancl\Tenancy\Listeners\BootstrapTenancy; use Stancl\Tenancy\Listeners\BootstrapTenancy;
use Stancl\Tenancy\Listeners\RevertToCentralContext; use Stancl\Tenancy\Listeners\RevertToCentralContext;
use Stancl\Tenancy\Tests\Etc\Tenant; use Stancl\Tenancy\Bootstrappers\CacheTagBootstrapper;
beforeEach(function () { beforeEach(function () {
config(['tenancy.bootstrappers' => []]); config(['tenancy.bootstrappers' => [CacheTagBootstrapper::class]]);
Event::listen(TenancyInitialized::class, BootstrapTenancy::class); Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
Event::listen(TenancyEnded::class, RevertToCentralContext::class); Event::listen(TenancyEnded::class, RevertToCentralContext::class);