8000 Update cache.md · PaolaRuby/laravel-permission@0ad6bf8 · GitHub 8000
[go: up one dir, main page]

Skip to content

Commit 0ad6bf8

Browse files
authored
Update cache.md
1 parent c2dee58 commit 0ad6bf8

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

docs/advanced-usage/cache.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ Role and Permission data are cached to speed up performance.
1010
When you **use the built-in functions** for manipulating roles and permissions, the cache is automatically reset for you, and relations are automatically reloaded for the current model record:
1111

1212
```php
13-
$user->assignRole('writer');
14-
$user->removeRole('writer');
15-
$user->syncRoles(params);
1613
$role->givePermissionTo('edit articles');
1714
$role->revokePermissionTo('edit articles');
1815
$role->syncPermissions(params);
@@ -25,6 +22,14 @@ HOWEVER, if you manipulate permission/role data directly in the database instead
2522

2623
Additionally, because the Role and Permission models are Eloquent models which implement the `RefreshesPermissionCache` trait, creating and deleting Roles and Permissions will automatically clear the cache. If you have created your own models which do not extend the default models then you will need to implement the trait yourself.
2724

25+
**NOTE: User-specific role/permission assignments are kept in-memory since v4.4.0, so the cache-reset is no longer called since v5.1.0 when updating User-related assignments.**
26+
Examples:
27+
```php
28+
// These do not call a cache-reset, because the User-related assignments are in-memory.
29+
$user->assignRole('writer');
30+
$user->removeRole('writer');
31+
$user->syncRoles(params);
32+
```
2833

2934
### Manual cache reset
3035
To manually reset the cache for this package, you can run the following in your app code:

0 commit comments

Comments
 (0)
0