Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • David Armitage 510 posts 2082 karma points
    May 18, 2021 @ 06:33
    David Armitage
    0

    Umbraco 8 Member Cache not updating after Save

    Hi people,

    So when I insert a new member in code the member cache is not updating. I literally have to go into the Umbraco backend and manually save this member before it is visible in the cache.

    So I add a new member with the following.

    public OnlineBookingMember InsertOnlineBookingMember(string email, string username, string name, string password, string propertyAppJson, bool initilizeLogin)
            {
                try
                {
                    IMember member = _memberService.CreateMemberWithIdentity(email, username, name,  "onlineBookingMember");
                    if (member != null)
                    {
                        member.SetValue("propertyApp", propertyAppJson);
                        _memberService.Save(member);
                        _memberService.SavePassword(member, password);
                        _memberService.AssignRole(member.Id, "Online Booking Member");
    
                        if (initilizeLogin)
                        {
                            if (Membership.ValidateUser(username, password))
                                FormsAuthentication.SetAuthCookie(username, false);
                        }
    
                        return _bookingMemberHelper.GetOnlineBookingMember(email);
                    }
                }
                catch (Exception e)
                {
                    _logger.Error<BookingBookingMemberService>(e, "InsertOnlineBookingMember | Exception: {0} | Message: {1}", e.InnerException != null ? e.InnerException.ToString() : "", e.Message != null ? e.Message.ToString() : "");
                }
    
                return null;
            }
    

    And then shortly after I have another controller action getting the member from cache but it just does not exist until I visit the backend and manually re-save the data.

    It almost feels like it is not saving and publishing but the membership only has a save unlike content which has both save and publish.

    IPublishedContent member = _membershipHelper.GetByEmail(email);
    

    I think this is a bug with Umbraco core but has anyone got any ideas to get around this. Possibly a easy way to refresh the member cache within code?

    Kind Regards

    David

  • AddWeb Solution Pvt. Ltd 109 posts 360 karma points
    May 20, 2021 @ 05:18
    AddWeb Solution Pvt. Ltd
    0

    Hello David,

    Try to rebuild the umbraco.config file

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies