kodeine / laravel-acl

Light-weight role-based permissions system for Laravel 6+ built in Auth system.
MIT License
787 stars 217 forks source link

No way to invalidate cache manually #263

Open apuatcfbd opened 3 years ago

apuatcfbd commented 3 years ago

By default this package has set cache time for 1 minute. If I update permissions for a role, this will be effective in next cache interval. But there's should be an option to manually invalidate the cache.

apuatcfbd commented 3 years ago

As there's no way to invalidate cache, I've created a trait to do so . Don't know if the keys I'm passing is absolutely correct or not. But it's working.

namespace App\Traits;

use Illuminate\Support\Facades\Cache;

trait AclCache
{
    public function invalidatePermissionCache(int $roleId) :void
    {
        Cache::forget("acl.getPermissionsInheritedById_{$roleId}");
        Cache::forget("acl.getPermissionsById_{$roleId}");
        Cache::forget("acl.getMergeById_{$roleId}");
    }

    public function invalidateRoleCache(int $userId) :void
    {
        Cache::forget("acl.getRolesById_{$userId}");
    }
}
kodeine commented 3 years ago

Can you please share a PR for this?