mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-13 17:44:03 +00:00
Finalize GlobalCache-related changes
This commit is contained in:
parent
a760c52ef2
commit
4129b2d956
3 changed files with 12 additions and 8 deletions
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
|
|
@ -16,7 +16,7 @@ jobs:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- laravel: "12.x-dev" # todo0 revert
|
- laravel: "^12.0"
|
||||||
php: "8.4"
|
php: "8.4"
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ namespace Stancl\Tenancy\Bootstrappers;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Cache\CacheManager;
|
use Illuminate\Cache\CacheManager;
|
||||||
|
use Illuminate\Cache\DatabaseStore;
|
||||||
use Illuminate\Config\Repository;
|
use Illuminate\Config\Repository;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
||||||
|
|
@ -13,10 +14,10 @@ use Stancl\Tenancy\Contracts\Tenant;
|
||||||
use Stancl\Tenancy\TenancyServiceProvider;
|
use Stancl\Tenancy\TenancyServiceProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This bootstrapper allows cache to be stored in the tenant databases by switching
|
* This bootstrapper allows cache to be stored in tenant databases by switching the database
|
||||||
* the database cache store's (and cache locks) connection.
|
* connection used by cache stores that use the database driver.
|
||||||
*
|
*
|
||||||
* Intended to be used with database driver-based cache stores, instead of CacheTenancyBootstrapper.
|
* Can be used instead of CacheTenancyBootstrapper.
|
||||||
*
|
*
|
||||||
* On bootstrap(), all database cache stores' connections are set to 'tenant'
|
* On bootstrap(), all database cache stores' connections are set to 'tenant'
|
||||||
* and the database cache stores are purged from the CacheManager's resolved stores.
|
* and the database cache stores are purged from the CacheManager's resolved stores.
|
||||||
|
|
@ -69,11 +70,11 @@ class DatabaseCacheBootstrapper implements TenancyBootstrapper
|
||||||
|
|
||||||
TenancyServiceProvider::$adjustCacheManagerUsing = static function (CacheManager $manager) use ($originalConnections) {
|
TenancyServiceProvider::$adjustCacheManagerUsing = static function (CacheManager $manager) use ($originalConnections) {
|
||||||
foreach ($originalConnections as $storeName => $connections) {
|
foreach ($originalConnections as $storeName => $connections) {
|
||||||
// @phpstan-ignore-next-line method.notFound
|
/** @var DatabaseStore $store */
|
||||||
$manager->store($storeName)->getStore()->setConnection(DB::connection($connections['connection']));
|
$store = $manager->store($storeName)->getStore();
|
||||||
|
|
||||||
// @phpstan-ignore-next-line method.notFound
|
$store->setConnection(DB::connection($connections['connection']));
|
||||||
$manager->store($storeName)->getStore()->setLockConnection(DB::connection($connections['lockConnection']));
|
$store->setLockConnection(DB::connection($connections['lockConnection']));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,9 @@ class TenancyServiceProvider extends ServiceProvider
|
||||||
// When we use the DatabaseTenancyBootstrapper, it changes the default connection,
|
// When we use the DatabaseTenancyBootstrapper, it changes the default connection,
|
||||||
// and therefore the connection of the database store that will be created when
|
// and therefore the connection of the database store that will be created when
|
||||||
// this new CacheManager is instantiated again.
|
// this new CacheManager is instantiated again.
|
||||||
|
//
|
||||||
|
// For that reason, we also adjust the relevant stores on this new CacheManager
|
||||||
|
// using the callback below. It is set by DatabaseCacheBootstrapper.
|
||||||
$manager = new CacheManager($app);
|
$manager = new CacheManager($app);
|
||||||
|
|
||||||
if (static::$adjustCacheManagerUsing !== null) {
|
if (static::$adjustCacheManagerUsing !== null) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue