cachingasp.net-boilerplatecache-invalidation

Refresh permissions from in-memory cache with ASP.NET Boilerplate


When I explicitly set a permission for a user in the database by running a SQL update script, the particular permission with the latest grant is not reflecting in the system. However when I recycle the IIS process or rebuild the solution, it only then seems to update.

It looks like the framework is using some kind of in-memory store for checking permissions.

Is there a "force refresh" function in ABP that I can call to refresh the in-memory store with the latest permissions from the database?

The weird thing is that when setting the permission via the front-end, the permission does work as expected without IIS recycling, so it definitely calls into some kind of function to update its cache.


Solution

  • You can inject ICacheManager and clear the cache:

    public void ForceRefresh()
    {
        _cacheManager.GetUserPermissionCache().Clear();
     // _cacheManager.GetRolePermissionCache().Clear();
    }