Skip to content

Conversation

@juhasev
Copy link
Contributor

@juhasev juhasev commented Sep 3, 2019

No description provided.

Copy link
Contributor Author

@juhasev juhasev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Load order should read 'CacheServiceProvider' as opposed to 'AppServiceProvider'

@juhasev
Copy link
Contributor Author

juhasev commented Sep 3, 2019

Also if user is using Redis as session store, the new CacheServiceProvider must be loaded before SessionServiceProvider.

@juhasev
Copy link
Contributor Author

juhasev commented Sep 3, 2019

The current example returns null from CLI as the config file driver.php doesn't even exist. Perhaps better alternative would be to set the $uuid variable simply to 'cli'.

@juhasev
Copy link
Contributor Author

juhasev commented Sep 3, 2019

Ended up going with Redis based caching for the domains. Join query is sort of expensive.

Cache::extend('redis_tenancy', function ($app) {

            if (PHP_SAPI === 'cli') {
                $uuid = 'cli';
            } else {

                $fqdn = request()->getHost();

                $uuid = Redis::get('domains:'.$fqdn);

                if ($uuid==0) {

                    $uuid = DB::table('hostnames')
                        ->select('websites.uuid')
                        ->join('websites', 'hostnames.website_id', '=', 'websites.id')
                        ->where('fqdn', $fqdn)
                        ->value('uuid');

                    Redis::set('domains:'.$fqdn, $uuid, 'ex', 60*60*24);
                }
            }

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

@ArlonAntonius
Copy link
Member

Feel like this should be moved to the docs regarding laravel-permissions 🤔

Copy link
Member

@ArlonAntonius ArlonAntonius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the one comment, perfect PR. Like I said in a comment, feel like this should be moved to the spatie/permissions tutorial we have, you could add a footnote/sidenote in the cache docs to refer to that specific section in the tutorial.

> Make sure the CacheServiceProvider is registered in `config/app.php` or else your driver will
not be available for use.

If you are using Spatie\Permission package and receive error about driver `redis_tenancy` is not supported,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spatie/laravel-permission please :)

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

Successfully merging this pull request may close these issues.

2 participants