laravel-acl icon indicating copy to clipboard operation
laravel-acl copied to clipboard

No way to invalidate cache manually

Open apuatcfbd opened this issue 4 years ago • 2 comments

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 avatar Mar 08 '21 09:03 apuatcfbd

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}");
    }
}

apuatcfbd avatar Mar 09 '21 12:03 apuatcfbd

Can you please share a PR for this?

kodeine avatar May 05 '21 23:05 kodeine