Role Caching/Persistence Issue after Direct Database Manipulation

Hello,

I am creating and deleting roles using the functions system.user.addRole and system.user.removeRole.
This works correctly, and if I use the function system.user.getRoles, everything is fine.

However, if I delete the roles directly from the "_roles" database table, the User Source locks up, and even the "_roles" table remains empty, the function "system.user.getRoles" still returns the last set of roles.
Even if I log out and log back in, the Startup Session Event is executed, but the roles remain the same as before emptying the "_roles" table.
If I execute a "system.user.addRole" again, the User Source gets reloaded and the result of getRoles is then returned correctly.

Similarly, if I deactivate the "User Source" and then reactivate it, the getRoles function also starts working again.

Regards

When you configure your user source, there is a “Cache Validation Timeout”. If it is non-zero, the user source will cache the last lookup for both roles and users and it won’t go back out to the database to refresh the cache until that time elapses OR you modify/delete/create a user or role at which time the cache will be flushed and re-populated.

So in your instance, since you added a role the cache was flushed. When you deactivated the user source, the user source was shutdown and the cache was deleted.

I hope this helps explain the behavior you saw.

PS - If you need the user source to immediately reflect the status of your database, then you will need to turn off the cache by setting “Cache Validation Timeout” to 0. This may lead to performance degradation depending on the number of roles and users and other factors.

3 Likes

Hello,

I see, then is normal what is happening. I tested the timeout and it works fine with 0.

Thanks