renoki-co/laravel-eloquent-query-cache

CLI and getCacheBaseTags method.

devajmeireles opened this issue · 1 comments

Hey, guys!

Unfortunately I don't have time to contribute a PR for this (really), so I wanted to report in hopes of someone contributing this PR.

Briefly commands via CLI are being impacted by the cache, I believe there should be a rule that escapes all cache if Laravel is in use via CLI.

I currently use the getCacheBaseTags method and in it I need to do something like:

    protected function getCacheBaseTags(): array
    {
        if (! Auth::check()) {
            return [
                (string) static::class,
            ];
        }

        return [
            'contacts_' . Auth::user()->id,
        ];
    }

If I don't get errors tied to not identifying the authenticated user, when we want to do something similar to that.

If I remove the first logic inside the method, features like db:seed give errors tied to the authenticated user. So if I were to contribute to a PR I would add a method that escapes the entire cache (and its checks) if using it via CLI / Artisan.

Avoiding cache for CLI would break queue workers and CLI commands that may want to use caching. The only thing you can do here would be to add a check at the app level just like you did.