Delay in refreshing application user group membership

When I modify group membership to application users (local users, not users in external directories):

private static final GroupService GROUP_SERVICE = ComponentAccessor.getComponent(GroupService.class);
private static final GroupManager GROUP_MANAGER = ComponentAccessor.getGroupManager();

// To remove groups
boolean removeResult = GROUP_SERVICE.removeUsersFromGroups(ctx, removeMapper);

// To add groups
boolean addResult = GROUP_SERVICE.addUsersToGroups(ctx, addGroups, users);

// To verify
GROUP_MANAGER.getGroupsForUser(u);

Both removeResult and addResult are true. But, the verification shows the groups before the modifications. If I perform the verification again later, then I can get the updated groups.

Why is there a delay, is the information cached? How can I flush the cache immediately?

Answer lies in source code of EditUserGroups.class. It uses CrowdService to read group membership, and it seems that one is not cached like GroupManager.

1 Like