Laravel-permission: [QUESTION] Why isn't there an option to fully disable the cache?

Created on 23 Jul 2020  路  4Comments  路  Source: spatie/laravel-permission

First off thank you for this package!

Problem

It is an awesome package and I really love how it helps me get things done.
However, I ran into a ( now known ) caching problem.

The issue isn't really that the package utilizes caching but rather when it utilizes the caching.
To explain a bit further.

We have an application that doesn't have an interface to remove permissions of roles. This resulted in unexpected behavior because I didn't remove the permissions using the package APIs.
When this happened I ran artisan config:clear because I suspected some sort of caching but, this didn't work.

How I finally resolved the problem

I managed to find the following issue: #1063 which stated the following command:
permission:cache-reset.

This fully resolved my issue but it didn't fully feel right.

Question

Wouldn't it be an idea to make sure that the permissions package cache will also get emptied when artisan cache:clear is run?
Or maybe even turning off the cache in a local environment but I don't know what the implications can be when this is done.

What also could help a lot is to make sure that the following text on the docs is bold so people actually get focussed to it.

https://docs.spatie.be/laravel-permission/v3/advanced-usage/cache/

HOWEVER, if you manipulate permission/role data directly in the database instead of calling the supplied methods, then you will not see the changes reflected in the application unless you manually reset the cache.

Final word

Lastly, I hope you can understand my irritation and reasoning on why I opened this issue.
I may be "the only" one to encounter this but I would love to be able to make sure that this issue gets a little bit more pointed out.

All 4 comments

Sorry you ran into confusion.

When this happened I ran artisan config:clear because I suspected some sort of caching but, this didn't work.

That's because config:clear only clears Laravel's configuration cache ... which is completely separate from the application cache.

Wouldn't it be an idea to make sure that the permissions package cache will also get emptied when artisan cache:clear is run?

It already does.
artisan cache:clear clears all caches in the entire application.
permission:cache-reset is effectively an alias for artisan cache:forget spatie.permission.cache which clears just the portion of the cache associated with this package's cache key (as configured in the config/permission.php config file).

Why isn't there an option to fully disable the cache?

Using the package's API (eg: the documented methods for interacting with permissions and roles) automatically takes care of updating cache when changes are made using the API.

For disabling the cache you could explore a few possibilities, in the package config file: set cache expiration time to 1 minute, or set the cache store to one that uses the Array cache driver.
Or, as you mentioned using local dev environment, you could set your application's .env CACHE_DRIVER to array so that everything is only cached into memory and not persisted (for the entire application).

@drbyte first off thank you for replying.

Hopefully, the issue wasn't interpreted as rude since that wasn't the intention.

That's because config:clear only clears Laravel's configuration cache ... which is completely separate from the application cache.
Shittt.... I didn't even notice this when I ran this.

Or, as you mentioned using local dev environment, you could set your application's .env CACHE_DRIVER to array so that everything is only cached into memory and not persisted (for the entire application).

Would it be an idea to include this in the docs perhaps?
I guess some sort of extra attention to the caching could be helpful for others.

Lastly thank you for your thorough response and your patience ( if that was needed ).

I've added some updates to the docs to improve clarity for essential points.
(I feel like it's not quite relevant for this package's docs to explain setting custom cache drivers though, so I left that out.)

Thanks for the suggestions!

Awesome thank you!

Have a nice day.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

neoreids picture neoreids  路  3Comments

devingray picture devingray  路  3Comments

MichalKrakow picture MichalKrakow  路  4Comments

hosseinnedaei picture hosseinnedaei  路  3Comments

feliperoan picture feliperoan  路  3Comments