Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CacheServiceeProvider tenant identification for background processes #1006

Open
juhasev opened this issue Jul 22, 2021 · 2 comments
Open

CacheServiceeProvider tenant identification for background processes #1006

juhasev opened this issue Jul 22, 2021 · 2 comments

Comments

@juhasev
Copy link

juhasev commented Jul 22, 2021

Hyn/Tenant 5.6 the example uses $app['config']['driver'] to get the tenant UUID, however it is always null. Does anybody know how to detect the Tenant in CLI operations like background processes? I have some background processes that need to clear Cached entries.

public function boot()
{
    Cache::extend('redis_tenancy', function ($app) {
        if (PHP_SAPI === 'cli') {
            $uuid = $app['config']['driver'];
        }

        return Cache::repository(new RedisStore(
                $app['redis'],
                $uuid,
                $app['config']['cache.stores.redis.connection']
            ));
    });
} 
@FloneJan
Copy link

I used another solution to solve this problem, which you can check in the AppServiceProvider boot() and fix by adding a cache prefix

    public function boot()
    {
        $website = \Hyn\Tenancy\Facades\TenancyFacade::website();
        if ($website) {
            Cache::setPrefix(Str::slug($website->uuid, '_') . '_cache');
        }
    }

@juhasev
Copy link
Author

juhasev commented Feb 10, 2022

Thanks @FloneJan I have to try this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants