Here is the use case for this issue. Let's say we have 2 sakai instances sak1 and sak2 and you are trying to create a new course site. After you create the site only the owner is enrolled on it (you have to wait the refresh), so the cache contains only one member.
The create operation is done in sak1, so the instance launch the event to notify the change. This event causes that the cache in sak1 is removed but also is launched in sak2 to remove the cache also.
Now sak1 runs the completeGet (the user clicks in the brand new site). The realm is not chached so, the run goes through the "else":
In that point the refresh is added to the queue, but the execution continues and ends adding the owner to the cache in this line:
Now sak1 has the realm cached again with only the owner but refresh is in the queue to update.
Let's say that sak2 do the same, so both instances has the realm cached with only one member and also in the queue to update.
Now the sak2 instance runs the refresh task, so it compares the provided users with the sakai database users and do the update. Because these two collections are different the cache will be removed in instance sak2, and everything looks right in sak2.
Now sak1 instance runs the refresh task, it compares again the provided user with the sakai database, but in this case boths collections are the same (sak2 already update the sakai database) !! So the result is that the cache is not removed in sak1 instance and you still having only one member in your site. You'll have to wait until caché expires in sak1 to see the members of the site (10 minutes or more).