Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to refresh Serenity.Authorization.UserDefinition after user logged on #2365

Closed
wirble opened this issue Jun 5, 2017 · 5 comments
Closed

Comments

@wirble
Copy link

wirble commented Jun 5, 2017

What is the best way for me to get an updated version of the UserDefinition of the currently logged on user.

When a user logged on, I have a background process that updates their profile on certain criteria. After this background process is done, what is the best way for me to update their cached UserDefinition and how?

Should I turn off the cache function, if so how can I do that?

Or is there a way to retrieve their current userdefinition instead of the cached version?

Thanks much.

@marcobisio
Copy link
Contributor

Try this way:

UserRetrieveService.RemoveCachedUser(....)

@wirble
Copy link
Author

wirble commented Jun 6, 2017

Thanks @marcobisio , where should I call that? In the AuthenticationService.cs file? So It doesn't cache it anymore...or right before I need it and Serenity will automatically retrieve the current user profile?

Or right after my background process is done and it will remove the current cache and force it to use the newer userdefinition?

@marcobisio
Copy link
Contributor

You're welcome @wirble.
You probably should do that every time your background process update a user, in order to force the cache expiration of such user, otherwise you can do some tuning on the expiration interval here (always UserRetrieveService):

public IUserDefinition ByUsername(string username)
{
    if (username.IsEmptyOrNull())
        return null;

    return TwoLevelCache.Get<UserDefinition>("UserByName_" + username.ToLowerInvariant(),
        TimeSpan.Zero, TimeSpan.FromDays(1), fld.GenerationKey, () =>
    {
        using (var connection = SqlConnections.NewByKey("Default"))
            return GetFirst(connection, new Criteria(fld.Username) == username);
    });
}

Bye

@wirble
Copy link
Author

wirble commented Jun 6, 2017

@marcobisio thanks again. I have seen the removecacheduser after the update in authenticationservice file. I wasnt sure if I had to call retrieve again, but i assume serenity will do that automatically.

@wirble wirble closed this as completed Jun 6, 2017
@ga5tan
Copy link

ga5tan commented Jul 31, 2018

@marcobisio
calling UserRetrieveService.RemoveCachedUser(id, usename) with both parameters filled in in SetInternalFields seemed to do the trick. Ofcourse, I had to forward browser to dashboard, to refresh UserMenu and display new display name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants