-
Notifications
You must be signed in to change notification settings - Fork 336
Caching
All queries executed by the bouncer are cached for the current request. For better performance, you may want to use cross-request caching. To enable cross-request caching, add this to your AppServiceProvider
's boot
method:
Bouncer::cache();
Warning: if you enable cross-request caching, you are responsible to refresh the cache whenever you make changes to user's abilities/roles. For how to refresh the cache, read refreshing the cache.
All queries executed by the bouncer are cached for the current request. If you enable cross-request caching, the cache will persist across different requests.
Whenever you need, you can fully refresh the bouncer's cache:
Bouncer::refresh();
Note: fully refreshing the cache for all users uses cache tags if they're available. Not all cache drivers support this. Refer to Laravel's documentation to see if your driver supports cache tags. If your driver does not support cache tags, calling
refresh
might be a little slow, depending on the amount of users in your system.
Alternatively, you can refresh the cache only for a specific user:
Bouncer::refreshFor($user);