1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 20:54:04 +00:00

Toggle cache tags

This commit is contained in:
lukinovec 2022-12-13 05:25:57 +01:00
parent 5c6226befc
commit 87efdd2954
5 changed files with 17 additions and 5 deletions

View file

@ -11,6 +11,8 @@ use Illuminate\Cache\Repository;
class CacheManager extends BaseCacheManager
{
public static bool $addTags = false;
/**
* Add tags and forward the call to the inner cache store.
*
@ -19,8 +21,7 @@ class CacheManager extends BaseCacheManager
*/
public function __call($method, $parameters)
{
// todo0 Make PrefixCacheTenancyBootstrapper work with tags
if (! tenancy()->initialized) {
if (! tenancy()->initialized || ! static::$addTags) {
return parent::__call($method, $parameters);
}

View file

@ -28,6 +28,7 @@ use Stancl\Tenancy\Bootstrappers\CacheTenancyBootstrapper;
use Stancl\Tenancy\Bootstrappers\RedisTenancyBootstrapper;
use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper;
use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper;
use Stancl\Tenancy\CacheManager;
beforeEach(function () {
$this->mockConsoleOutput = false;
@ -75,6 +76,8 @@ test('database data is separated', function () {
});
test('cache data is separated', function (string $bootstrapper) {
CacheManager::$addTags = true;
config([
'tenancy.bootstrappers' => [$bootstrapper],
'cache.default' => 'redis',
@ -114,7 +117,7 @@ test('cache data is separated', function (string $bootstrapper) {
})->with([
'CacheTenancyBootstrapper' => CacheTenancyBootstrapper::class,
'PrefixCacheTenancyBootstrapper' => PrefixCacheTenancyBootstrapper::class,
]);
])->group('bootstrapper');
test('redis data is separated', function () {
config(['tenancy.bootstrappers' => [

View file

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

View file

@ -4,6 +4,7 @@ declare(strict_types=1);
use Illuminate\Support\Facades\Event;
use Stancl\Tenancy\Bootstrappers\CacheTenancyBootstrapper;
use Stancl\Tenancy\CacheManager;
use Stancl\Tenancy\Events\TenancyEnded;
use Stancl\Tenancy\Events\TenancyInitialized;
use Stancl\Tenancy\Facades\GlobalCache;
@ -16,6 +17,8 @@ beforeEach(function () {
CacheTenancyBootstrapper::class,
]]);
CacheManager::$addTags = true;
Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
Event::listen(TenancyEnded::class, RevertToCentralContext::class);
});

View file

@ -20,6 +20,8 @@ beforeEach(function () {
'cache.default' => 'redis',
]);
TenancyCacheManager::$addTags = false;
Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
Event::listen(TenancyEnded::class, RevertToCentralContext::class);
});